********************************************************************************
** 	TITLE:		gb2005_bes_contact_networks		                              **
**  AUTHOR:	    Philippe Mongrain                                             **
**	DATA:       2005BES_PRE					                                  **
**	DATE:		October 2022 					                              **	
**	VERSION:	Stata 16					                                  **
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close
log using "gb2005_bes_contact_networks", replace

* Open dataset

use "2005BES_PRE.dta", clear


***********************
** DISTRICT OUTCOMES **
***********************

* Clean district names

gen district_name = hseat05
replace district_name = upper(district_name)
replace district_name = subinstr(district_name," AND "," & ",.)
replace district_name = subinstr(district_name,"  "," ",.)

replace district_name = "AIRDRIE & SHOTTS" if district_name == "AIRDRIE AND SHOTTS"
replace district_name = "BANFF & BUCHAN" if district_name == "BANFF AND BUCHAN"
replace district_name = "DUMFRIES & GALLOWAY" if district_name == "DUMFRIES AND GALLOWAY"
replace district_name = "DUMFRIESSHIRE, CLYDESDALE & TWEEDDALE" if district_name == "DUMFRIESSHIRE, CLYDESDALE AND TWEEDDALE"
replace district_name = "EDINBURGH NORTH & LEITH" if district_name == "EDINBURGH NORTH AND LEITH"
replace district_name = "DUNFERMLINE & WEST FIFE" if district_name == "DUNFERMLINE AND WEST FIFE"
replace district_name = "EDINBURGH NORTH & LEITH" if district_name == "EDINBURGH NORTH AND LEITH"
replace district_name = "LANARCK & HAMILTON EAST" if district_name == "LANARCK AND HAMILTON EAST"
replace district_name = "OCHIL & SOUTH PERTHSHIRE" if district_name == "OCHIL AND SOUTH PERTHSHIRE"
replace district_name = "PERTH & NORTH PERTHSHIRE" if district_name == "PERTH AND NORTH PERTHSHIRE"
replace district_name = "RUTHERGLEN & HAMILTON WEST" if district_name == "RUTHERGLEN AND HAMILTON WEST"

encode district_name, gen(district_code)

* Note: 1 = Conservative, 2 = Labour, 3 = Liberal Democrats, 4 = SNP, 5 = Plaid Cymru, 6 = UKIP, 7 = Greens
							
gen district_outcome = .

replace district_outcome = 2 if district_name == "BEDFORD"
replace district_outcome = 1 if district_name == "READING EAST"
replace district_outcome = 1 if district_name == "EPSOM & EWELL"
replace district_outcome = 1 if district_name == "ESHER & WALTON"
replace district_outcome = 1 if district_name == "GUILDFORD"
replace district_outcome = 1 if district_name == "MOLE VALLEY"
replace district_outcome = 1 if district_name == "REIGATE"
replace district_outcome = 1 if district_name == "RUNNYMEDE & WEYBRIDGE"
replace district_outcome = 1 if district_name == "SURREY SOUTH WEST"
replace district_outcome = 1 if district_name == "SPELTHORNE"
replace district_outcome = 1 if district_name == "SURREY HEATH"
replace district_outcome = 1 if district_name == "WOKING"
replace district_outcome = 2 if district_name == "READING WEST"
replace district_outcome = 1 if district_name == "ARUNDEL & SOUTH DOWNS"
replace district_outcome = 1 if district_name == "BOGNOR REGIS & LITTLEHAMPTON"
replace district_outcome = 1 if district_name == "CHICHESTER"
replace district_outcome = 2 if district_name == "CRAWLEY"
replace district_outcome = 1 if district_name == "EAST WORTHING & SHOREHAM"
replace district_outcome = 1 if district_name == "HORSHAM"
replace district_outcome = 1 if district_name == "MID SUSSEX"
replace district_outcome = 1 if district_name == "WORTHING WEST"
replace district_outcome = 3 if district_name == "CAMBRIDGE"
replace district_outcome = 1 if district_name == "HUNTINGDON"
replace district_outcome = 2 if district_name == "SLOUGH"
replace district_outcome = 1 if district_name == "NORTH EAST CAMBRIDGESHIRE"
replace district_outcome = 1 if district_name == "NORTH WEST CAMBRIDGESHIRE"
replace district_outcome = 1 if district_name == "PETERBOROUGH"
replace district_outcome = 1 if district_name == "SOUTH CAMBRIDGESHIRE"
replace district_outcome = 1 if district_name == "SOUTH EAST CAMBRIDGESHIRE"
replace district_outcome = 2 if district_name == "GREAT YARMOUTH"
replace district_outcome = 1 if district_name == "MID NORFOLK"
replace district_outcome = 3 if district_name == "NORTH NORFOLK"
replace district_outcome = 1 if district_name == "NORFOLK NORTH WEST"
replace district_outcome = 2 if district_name == "NORWICH NORTH"
replace district_outcome = 1 if district_name == "WINDSOR"
replace district_outcome = 2 if district_name == "NORWICH SOUTH"
replace district_outcome = 1 if district_name == "SOUTH NORFOLK"
replace district_outcome = 1 if district_name == "NORFOLK SOUTH WEST"
replace district_outcome = 1 if district_name == "BURY ST EDMUNDS"
replace district_outcome = 1 if district_name == "CENTRAL SUFFOLK & NORTH IPSWICH"
replace district_outcome = 2 if district_name == "IPSWICH"
replace district_outcome = 1 if district_name == "SOUTH SUFFOLK"
replace district_outcome = 1 if district_name == "SUFFOLK COASTAL"
replace district_outcome = 2 if district_name == "WAVENEY"
replace district_outcome = 1 if district_name == "WEST SUFFOLK"
replace district_outcome = 1 if district_name == "WOKINGHAM"
replace district_outcome = 2 if district_name == "BARKING"
replace district_outcome = 2 if district_name == "BATTERSEA"
replace district_outcome = 1 if district_name == "BECKENHAM"
replace district_outcome = 9 if district_name == "BETHNAL GREEN & BOW"
replace district_outcome = 1 if district_name == "BEXLEYHEATH & CRAYFORD"
replace district_outcome = 3 if district_name == "BRENT EAST"
replace district_outcome = 2 if district_name == "BRENT NORTH"
replace district_outcome = 2 if district_name == "BRENT SOUTH"
replace district_outcome = 2 if district_name == "BRENTFORD & ISLEWORTH"
replace district_outcome = 1 if district_name == "BROMLEY & CHISLEHURST"
replace district_outcome = 1 if district_name == "AYLESBURY"
replace district_outcome = 2 if district_name == "CAMBERWELL & PECKHAM"
replace district_outcome = 3 if district_name == "CARSHALTON & WALLINGTON"
replace district_outcome = 1 if district_name == "CHINGFORD & WOODFORD GREEN"
replace district_outcome = 1 if district_name == "CHIPPING BARNET"
replace district_outcome = 1 if district_name == "CITIES OF LONDON & WESTMINSTER"
replace district_outcome = 1 if district_name == "CROYDON CENTRAL"
replace district_outcome = 2 if district_name == "CROYDON NORTH"
replace district_outcome = 1 if district_name == "CROYDON SOUTH"
replace district_outcome = 2 if district_name == "DAGENHAM"
replace district_outcome = 2 if district_name == "DULWICH & WEST NORWOOD"
replace district_outcome = 1 if district_name == "BEACONSFIELD"
replace district_outcome = 2 if district_name == "EALING, SOUTHALL"
replace district_outcome = 2 if district_name == "EALING NORTH"
replace district_outcome = 2 if district_name == "EALING, ACTON & SHEPHERD'S BUSH"
replace district_outcome = 2 if district_name == "EAST HAM"
replace district_outcome = 2 if district_name == "EDMONTON"
replace district_outcome = 2 if district_name == "ELTHAM"
replace district_outcome = 2 if district_name == "ENFIELD NORTH"
replace district_outcome = 1 if district_name == "ENFIELD, SOUTHGATE"
replace district_outcome = 2 if district_name == "ERITH & THAMESMEAD"
replace district_outcome = 2 if district_name == "FELTHAM & HESTON"
replace district_outcome = 1 if district_name == "BUCKINGHAM"
replace district_outcome = 2 if district_name == "FINCHLEY & GOLDERS GREEN"
replace district_outcome = 2 if district_name == "GREENWICH & WOOLWICH"
replace district_outcome = 2 if district_name == "HACKNEY NORTH & STOKE NEWINGTON"
replace district_outcome = 2 if district_name == "HACKNEY SOUTH & SHOREDITCH"
replace district_outcome = 1 if district_name == "HAMMERSMITH & FULHAM"
replace district_outcome = 2 if district_name == "HAMPSTEAD & HIGHGATE"
replace district_outcome = 2 if district_name == "HARROW EAST"
replace district_outcome = 2 if district_name == "HARROW WEST"
replace district_outcome = 2 if district_name == "HAYES & HARLINGTON"
replace district_outcome = 2 if district_name == "HENDON"
replace district_outcome = 1 if district_name == "CHESHAM & AMERSHAM"
replace district_outcome = 2 if district_name == "HOLBORN & ST PANCRAS"
replace district_outcome = 1 if district_name == "HORNCHURCH"
replace district_outcome = 3 if district_name == "HORNSEY & WOOD GREEN"
replace district_outcome = 1 if district_name == "ILFORD NORTH"
replace district_outcome = 2 if district_name == "ILFORD SOUTH"
replace district_outcome = 2 if district_name == "ISLINGTON NORTH"
replace district_outcome = 2 if district_name == "ISLINGTON SOUTH & FINSBURY"
replace district_outcome = 1 if district_name == "KENSINGTON & CHELSEA"
replace district_outcome = 3 if district_name == "KINGSTON & SURBITON"
replace district_outcome = 2 if district_name == "LEWISHAM EAST"
replace district_outcome = 2 if district_name == "MILTON KEYNES SOUTH WEST"
replace district_outcome = 2 if district_name == "LEWISHAM WEST"
replace district_outcome = 2 if district_name == "LEWISHAM, DEPTFORD"
replace district_outcome = 2 if district_name == "LEYTON & WANSTEAD"
replace district_outcome = 2 if district_name == "MITCHAM & MORDEN"
replace district_outcome = 3 if district_name == "SOUTHWARK NORTH & BERMONDSEY"
replace district_outcome = 1 if district_name == "OLD BEXLEY & SIDCUP"
replace district_outcome = 1 if district_name == "ORPINGTON"
replace district_outcome = 2 if district_name == "POPLAR & CANNING TOWN"
replace district_outcome = 1 if district_name == "PUTNEY"
replace district_outcome = 2 if district_name == "REGENT'S PARK & KENSINGTON NORTH"
replace district_outcome = 2 if district_name == "LUTON NORTH"
replace district_outcome = 1 if district_name == "NORTH EAST MILTON KEYNES"
replace district_outcome = 3 if district_name == "RICHMOND PARK"
replace district_outcome = 1 if district_name == "ROMFORD"
replace district_outcome = 1 if district_name == "RUISLIP - NORTHWOOD"
replace district_outcome = 2 if district_name == "STREATHAM"
replace district_outcome = 3 if district_name == "SUTTON & CHEAM"
replace district_outcome = 2 if district_name == "TOOTING"
replace district_outcome = 2 if district_name == "TOTTENHAM"
replace district_outcome = 3 if district_name == "TWICKENHAM"
replace district_outcome = 1 if district_name == "UPMINSTER"
replace district_outcome = 1 if district_name == "UXBRIDGE"
replace district_outcome = 1 if district_name == "WYCOMBE"
replace district_outcome = 2 if district_name == "VAUXHALL"
replace district_outcome = 2 if district_name == "WALTHAMSTOW"
replace district_outcome = 2 if district_name == "WEST HAM"
replace district_outcome = 1 if district_name == "WIMBLEDON"
replace district_outcome = 3 if district_name == "BATH"
replace district_outcome = 2 if district_name == "BRISTOL EAST"
replace district_outcome = 2 if district_name == "BRISTOL NORTH WEST"
replace district_outcome = 2 if district_name == "BRISTOL SOUTH"
replace district_outcome = 3 if district_name == "BRISTOL WEST"
replace district_outcome = 2 if district_name == "KINGSWOOD"
replace district_outcome = 1 if district_name == "BEXHILL & BATTLE"
replace district_outcome = 3 if district_name == "NORTHAVON"
replace district_outcome = 2 if district_name == "WANSDYKE"
replace district_outcome = 1 if district_name == "WESTON-SUPER-MARE"
replace district_outcome = 1 if district_name == "WOODSPRING"
replace district_outcome = 3 if district_name == "FALMOUTH & CAMBORNE"
replace district_outcome = 3 if district_name == "CORNWALL NORTH"
replace district_outcome = 3 if district_name == "SOUTH EAST CORNWALL"
replace district_outcome = 3 if district_name == "ST IVES"
replace district_outcome = 3 if district_name == "TRURO & ST AUSTELL"
replace district_outcome = 1 if district_name == "EAST DEVON"
replace district_outcome = 2 if district_name == "BRIGHTON, KEMPTOWN"
replace district_outcome = 2 if district_name == "EXETER"
replace district_outcome = 3 if district_name == "NORTH DEVON"
replace district_outcome = 2 if district_name == "PLYMOUTH, DEVONPORT"
replace district_outcome = 2 if district_name == "PLYMOUTH, SUTTON"
replace district_outcome = 1 if district_name == "SOUTH WEST DEVON"
replace district_outcome = 3 if district_name == "TEIGNBRIDGE"
replace district_outcome = 1 if district_name == "TIVERTON & HONITON"
replace district_outcome = 3 if district_name == "TORBAY"
replace district_outcome = 1 if district_name == "TORRIDGE & WEST DEVON"
replace district_outcome = 1 if district_name == "TOTNES"
replace district_outcome = 2 if district_name == "BRIGHTON, PAVILION"
replace district_outcome = 1 if district_name == "BOURNEMOUTH EAST"
replace district_outcome = 1 if district_name == "BOURNEMOUTH WEST"
replace district_outcome = 1 if district_name == "CHRISTCHURCH"
replace district_outcome = 3 if district_name == "MID DORSET & NORTH POOLE"
replace district_outcome = 1 if district_name == "NORTH DORSET"
replace district_outcome = 1 if district_name == "POOLE"
replace district_outcome = 2 if district_name == "SOUTH DORSET"
replace district_outcome = 1 if district_name == "DORSET WEST"
replace district_outcome = 3 if district_name == "CHELTENHAM"
replace district_outcome = 1 if district_name == "COTSWOLD"
replace district_outcome = 1 if district_name == "EASTBOURNE"
replace district_outcome = 1 if district_name == "FOREST OF DEAN"
replace district_outcome = 2 if district_name == "GLOUCESTER"
replace district_outcome = 2 if district_name == "STROUD"
replace district_outcome = 1 if district_name == "TEWKESBURY"
replace district_outcome = 1 if district_name == "BRIDGWATER"
replace district_outcome = 3 if district_name == "SOMERTON & FROME"
replace district_outcome = 3 if district_name == "TAUNTON"
replace district_outcome = 1 if district_name == "WELLS"
replace district_outcome = 3 if district_name == "YEOVIL"
replace district_outcome = 1 if district_name == "DEVIZES"
replace district_outcome = 2 if district_name == "HASTINGS & RYE"
replace district_outcome = 2 if district_name == "SWINDON NORTH"
replace district_outcome = 1 if district_name == "NORTH WILTSHIRE"
replace district_outcome = 1 if district_name == "SALISBURY"
replace district_outcome = 2 if district_name == "SOUTH SWINDON"
replace district_outcome = 1 if district_name == "WESTBURY"
replace district_outcome = 1 if district_name == "BROMSGROVE"
replace district_outcome = 3 if district_name == "HEREFORD"
replace district_outcome = 1 if district_name == "LEOMINSTER"
replace district_outcome = 1 if district_name == "MID WORCESTERSHIRE"
replace district_outcome = 2 if district_name == "REDDITCH"
replace district_outcome = 2 if district_name == "HOVE"
replace district_outcome = 1 if district_name == "WEST WORCESTERSHIRE"
replace district_outcome = 2 if district_name == "WORCESTER"
replace district_outcome = 9 if district_name == "WYRE FOREST"
replace district_outcome = 1 if district_name == "LUDLOW"
replace district_outcome = 1 if district_name == "NORTH SHROPSHIRE"
replace district_outcome = 1 if district_name == "SHREWSBURY & ATCHAM"
replace district_outcome = 2 if district_name == "TELFORD"
replace district_outcome = 1 if district_name == "WREKIN, THE"
replace district_outcome = 2 if district_name == "BURTON"
replace district_outcome = 2 if district_name == "CANNOCK CHASE"
replace district_outcome = 3 if district_name == "LEWES"
replace district_outcome = 1 if district_name == "LICHFIELD"
replace district_outcome = 2 if district_name == "NEWCASTLE-UNDER-LYME"
replace district_outcome = 1 if district_name == "SOUTH STAFFORDSHIRE"
replace district_outcome = 2 if district_name == "STAFFORD"
replace district_outcome = 2 if district_name == "STAFFORDSHIRE MOORLANDS"
replace district_outcome = 2 if district_name == "STOKE-ON-TRENT CENTRAL"
replace district_outcome = 2 if district_name == "STOKE-ON-TRENT NORTH"
replace district_outcome = 2 if district_name == "STOKE-ON-TRENT SOUTH"
replace district_outcome = 1 if district_name == "STONE"
replace district_outcome = 2 if district_name == "TAMWORTH"
replace district_outcome = 1 if district_name == "WEALDEN"
replace district_outcome = 2 if district_name == "NORTH WARWICKSHIRE"
replace district_outcome = 2 if district_name == "NUNEATON"
replace district_outcome = 1 if district_name == "RUGBY & KENILWORTH"
replace district_outcome = 1 if district_name == "STRATFORD ON AVON"
replace district_outcome = 2 if district_name == "WARWICK & LEAMINGTON"
replace district_outcome = 1 if district_name == "ALDRIDGE - BROWNHILLS"
replace district_outcome = 2 if district_name == "BIRMINGHAM, EDGBASTON"
replace district_outcome = 2 if district_name == "BIRMINGHAM, ERDINGTON"
replace district_outcome = 2 if district_name == "BIRMINGHAM, HALL GREEN"
replace district_outcome = 2 if district_name == "BIRMINGHAM, HODGE HILL"
replace district_outcome = 2 if district_name == "LUTON SOUTH"
replace district_outcome = 2 if district_name == "BASILDON"
replace district_outcome = 2 if district_name == "BIRMINGHAM, LADYWOOD"
replace district_outcome = 2 if district_name == "BIRMINGHAM, NORTHFIELD"
replace district_outcome = 2 if district_name == "BIRMINGHAM, PERRY BARR"
replace district_outcome = 2 if district_name == "BIRMINGHAM, SELLY OAK"
replace district_outcome = 2 if district_name == "BIRMINGHAM, SPARKBROOK & SMALL HEATH"
replace district_outcome = 3 if district_name == "BIRMINGHAM, YARDLEY"
replace district_outcome = 2 if district_name == "COVENTRY NORTH EAST"
replace district_outcome = 2 if district_name == "COVENTRY NORTH WEST"
replace district_outcome = 2 if district_name == "COVENTRY SOUTH"
replace district_outcome = 2 if district_name == "DUDLEY NORTH"
replace district_outcome = 1 if district_name == "BILLERICAY"
replace district_outcome = 2 if district_name == "DUDLEY SOUTH"
replace district_outcome = 2 if district_name == "HALESOWEN & ROWLEY REGIS"
replace district_outcome = 1 if district_name == "MERIDEN"
replace district_outcome = 3 if district_name == "SOLIHULL"
replace district_outcome = 2 if district_name == "STOURBRIDGE"
replace district_outcome = 1 if district_name == "SUTTON COLDFIELD"
replace district_outcome = 2 if district_name == "WALSALL NORTH"
replace district_outcome = 2 if district_name == "WALSALL SOUTH"
replace district_outcome = 2 if district_name == "WARLEY"
replace district_outcome = 2 if district_name == "WEST BROMWICH EAST"
replace district_outcome = 1 if district_name == "BRAINTREE"
replace district_outcome = 2 if district_name == "WEST BROMWICH WEST"
replace district_outcome = 2 if district_name == "WOLVERHAMPTON NORTH EAST"
replace district_outcome = 2 if district_name == "WOLVERHAMPTON SOUTH EAST"
replace district_outcome = 2 if district_name == "WOLVERHAMPTON SOUTH WEST"
replace district_outcome = 2 if district_name == "AMBER VALLEY"
replace district_outcome = 2 if district_name == "BOLSOVER"
replace district_outcome = 3 if district_name == "CHESTERFIELD"
replace district_outcome = 2 if district_name == "DERBY NORTH"
replace district_outcome = 2 if district_name == "DERBY SOUTH"
replace district_outcome = 2 if district_name == "EREWASH"
replace district_outcome = 1 if district_name == "BRENTWOOD & ONGAR"
replace district_outcome = 2 if district_name == "HIGH PEAK"
replace district_outcome = 2 if district_name == "NORTH EAST DERBYSHIRE"
replace district_outcome = 2 if district_name == "SOUTH DERBYSHIRE"
replace district_outcome = 1 if district_name == "WEST DERBYSHIRE"
replace district_outcome = 1 if district_name == "BLABY"
replace district_outcome = 1 if district_name == "BOSWORTH"
replace district_outcome = 1 if district_name == "CHARNWOOD"
replace district_outcome = 1 if district_name == "HARBOROUGH"
replace district_outcome = 2 if district_name == "LEICESTER EAST"
replace district_outcome = 2 if district_name == "LEICESTER SOUTH"
replace district_outcome = 1 if district_name == "CASTLE POINT"
replace district_outcome = 2 if district_name == "LEICESTER WEST"
replace district_outcome = 2 if district_name == "LOUGHBOROUGH"
replace district_outcome = 2 if district_name == "NORTH WEST LEICESTERSHIRE"
replace district_outcome = 1 if district_name == "RUTLAND & MELTON"
replace district_outcome = 1 if district_name == "BOSTON & SKEGNESS"
replace district_outcome = 1 if district_name == "GAINSBOROUGH"
replace district_outcome = 1 if district_name == "GRANTHAM & STAMFORD"
replace district_outcome = 2 if district_name == "LINCOLN"
replace district_outcome = 1 if district_name == "LOUTH & HORNCASTLE"
replace district_outcome = 1 if district_name == "SLEAFORD & NORTH HYKEHAM"
replace district_outcome = 3 if district_name == "COLCHESTER"
replace district_outcome = 1 if district_name == "SOUTH HOLLAND & THE DEEPINGS"
replace district_outcome = 2 if district_name == "CORBY"
replace district_outcome = 1 if district_name == "DAVENTRY"
replace district_outcome = 1 if district_name == "KETTERING"
replace district_outcome = 2 if district_name == "NORTHAMPTON NORTH"
replace district_outcome = 1 if district_name == "NORTHAMPTON SOUTH"
replace district_outcome = 1 if district_name == "WELLINGBOROUGH"
replace district_outcome = 2 if district_name == "ASHFIELD"
replace district_outcome = 2 if district_name == "BASSETLAW"
replace district_outcome = 2 if district_name == "BROXTOWE"
replace district_outcome = 1 if district_name == "EPPING FOREST"
replace district_outcome = 2 if district_name == "GEDLING"
replace district_outcome = 2 if district_name == "MANSFIELD"
replace district_outcome = 1 if district_name == "NEWARK"
replace district_outcome = 2 if district_name == "NOTTINGHAM EAST"
replace district_outcome = 2 if district_name == "NOTTINGHAM NORTH"
replace district_outcome = 2 if district_name == "NOTTINGHAM SOUTH"
replace district_outcome = 1 if district_name == "RUSHCLIFFE"
replace district_outcome = 2 if district_name == "SHERWOOD"
replace district_outcome = 1 if district_name == "BEVERLEY & HOLDERNESS"
replace district_outcome = 2 if district_name == "BRIGG & GOOLE"
replace district_outcome = 2 if district_name == "HARLOW"
replace district_outcome = 2 if district_name == "CLEETHORPES"
replace district_outcome = 1 if district_name == "EAST YORKSHIRE"
replace district_outcome = 2 if district_name == "GREAT GRIMSBY"
replace district_outcome = 1 if district_name == "HALTEMPRICE & HOWDEN"
replace district_outcome = 2 if district_name == "KINGSTON UPON HULL EAST"
replace district_outcome = 2 if district_name == "KINGSTON UPON HULL NORTH"
replace district_outcome = 2 if district_name == "KINGSTON UPON HULL WEST & HESSLE"
replace district_outcome = 2 if district_name == "SCUNTHORPE"
replace district_outcome = 3 if district_name == "HARROGATE & KNARESBOROUGH"
replace district_outcome = 1 if district_name == "RICHMOND (YORKS)"
replace district_outcome = 1 if district_name == "HARWICH"
replace district_outcome = 1 if district_name == "RYEDALE"
replace district_outcome = 1 if district_name == "SCARBOROUGH & WHITBY"
replace district_outcome = 2 if district_name == "SELBY"
replace district_outcome = 1 if district_name == "SKIPTON & RIPON"
replace district_outcome = 1 if district_name == "VALE OF YORK"
replace district_outcome = 2 if district_name == "YORK, CITY OF"
replace district_outcome = 2 if district_name == "BARNSLEY CENTRAL"
replace district_outcome = 2 if district_name == "BARNSLEY EAST & MEXBOROUGH"
replace district_outcome = 2 if district_name == "BARNSLEY WEST & PENISTONE"
replace district_outcome = 2 if district_name == "DON VALLEY"
replace district_outcome = 1 if district_name == "MALDON & EAST CHELMSFORD"
replace district_outcome = 2 if district_name == "DONCASTER CENTRAL"
replace district_outcome = 2 if district_name == "DONCASTER NORTH"
replace district_outcome = 2 if district_name == "ROTHER VALLEY"
replace district_outcome = 2 if district_name == "ROTHERHAM"
replace district_outcome = 2 if district_name == "SHEFFIELD, ATTERCLIFFE"
replace district_outcome = 2 if district_name == "SHEFFIELD, BRIGHTSIDE"
replace district_outcome = 2 if district_name == "SHEFFIELD CENTRAL"
replace district_outcome = 3 if district_name == "SHEFFIELD, HALLAM"
replace district_outcome = 2 if district_name == "SHEFFIELD, HEELEY"
replace district_outcome = 2 if district_name == "SHEFFIELD, HILLSBOROUGH"
replace district_outcome = 1 if district_name == "MID BEDFORDSHIRE"
replace district_outcome = 1 if district_name == "NORTH ESSEX"
replace district_outcome = 2 if district_name == "WENTWORTH"
replace district_outcome = 2 if district_name == "BATLEY & SPEN"
replace district_outcome = 2 if district_name == "BRADFORD NORTH"
replace district_outcome = 2 if district_name == "BRADFORD SOUTH"
replace district_outcome = 2 if district_name == "BRADFORD WEST"
replace district_outcome = 2 if district_name == "CALDER VALLEY"
replace district_outcome = 2 if district_name == "COLNE VALLEY"
replace district_outcome = 2 if district_name == "DEWSBURY"
replace district_outcome = 2 if district_name == "ELMET"
replace district_outcome = 2 if district_name == "HALIFAX"
replace district_outcome = 1 if district_name == "RAYLEIGH"
replace district_outcome = 2 if district_name == "HEMSWORTH"
replace district_outcome = 2 if district_name == "HUDDERSFIELD"
replace district_outcome = 2 if district_name == "KEIGHLEY"
replace district_outcome = 2 if district_name == "LEEDS CENTRAL"
replace district_outcome = 2 if district_name == "LEEDS EAST"
replace district_outcome = 2 if district_name == "LEEDS NORTH EAST"
replace district_outcome = 3 if district_name == "LEEDS NORTH WEST"
replace district_outcome = 2 if district_name == "LEEDS WEST"
replace district_outcome = 2 if district_name == "MORLEY & ROTHWELL"
replace district_outcome = 2 if district_name == "NORMANTON"
replace district_outcome = 1 if district_name == "ROCHFORD & SOUTHEND EAST"
replace district_outcome = 2 if district_name == "PONTEFRACT & CASTLEFORD"
replace district_outcome = 2 if district_name == "PUDSEY"
replace district_outcome = 1 if district_name == "SHIPLEY"
replace district_outcome = 2 if district_name == "WAKEFIELD"
replace district_outcome = 2 if district_name == "CHESTER, CITY OF"
replace district_outcome = 1 if district_name == "CONGLETON"
replace district_outcome = 2 if district_name == "CREWE & NANTWICH"
replace district_outcome = 1 if district_name == "EDDISBURY"
replace district_outcome = 2 if district_name == "ELLESMERE PORT & NESTON"
replace district_outcome = 2 if district_name == "HALTON"
replace district_outcome = 1 if district_name == "SAFFRON WALDEN"
replace district_outcome = 1 if district_name == "MACCLESFIELD"
replace district_outcome = 1 if district_name == "TATTON"
replace district_outcome = 2 if district_name == "WARRINGTON NORTH"
replace district_outcome = 2 if district_name == "WARRINGTON SOUTH"
replace district_outcome = 2 if district_name == "WEAVER VALE"
replace district_outcome = 1 if district_name == "ALTRINCHAM & SALE WEST"
replace district_outcome = 2 if district_name == "ASHTON-UNDER-LYNE"
replace district_outcome = 2 if district_name == "BOLTON NORTH EAST"
replace district_outcome = 2 if district_name == "BOLTON SOUTH EAST"
replace district_outcome = 2 if district_name == "BOLTON WEST"
replace district_outcome = 1 if district_name == "SOUTHEND WEST"
replace district_outcome = 2 if district_name == "BURY NORTH"
replace district_outcome = 2 if district_name == "BURY SOUTH"
replace district_outcome = 3 if district_name == "CHEADLE"
replace district_outcome = 2 if district_name == "DENTON & REDDISH"
replace district_outcome = 2 if district_name == "ECCLES"
replace district_outcome = 3 if district_name == "HAZEL GROVE"
replace district_outcome = 2 if district_name == "HEYWOOD & MIDDLETON"
replace district_outcome = 2 if district_name == "LEIGH"
replace district_outcome = 2 if district_name == "MAKERFIELD"
replace district_outcome = 2 if district_name == "MANCHESTER, BLACKLEY"
replace district_outcome = 2 if district_name == "THURROCK"
replace district_outcome = 2 if district_name == "MANCHESTER CENTRAL"
replace district_outcome = 2 if district_name == "MANCHESTER, GORTON"
replace district_outcome = 3 if district_name == "MANCHESTER, WITHINGTON"
replace district_outcome = 2 if district_name == "OLDHAM EAST & SADDLEWORTH"
replace district_outcome = 2 if district_name == "OLDHAM WEST & ROYTON"
replace district_outcome = 3 if district_name == "ROCHDALE"
replace district_outcome = 2 if district_name == "SALFORD"
replace district_outcome = 2 if district_name == "STALYBRIDGE & HYDE"
replace district_outcome = 2 if district_name == "STOCKPORT"
replace district_outcome = 2 if district_name == "STRETFORD & URMSTON"
replace district_outcome = 1 if district_name == "WEST CHELMSFORD"
replace district_outcome = 2 if district_name == "WIGAN"
replace district_outcome = 2 if district_name == "WORSLEY"
replace district_outcome = 2 if district_name == "WYTHENSHAWE & SALE EAST"
replace district_outcome = 2 if district_name == "BLACKBURN"
replace district_outcome = 2 if district_name == "BLACKPOOL NORTH & FLEETWOOD"
replace district_outcome = 2 if district_name == "BLACKPOOL SOUTH"
replace district_outcome = 2 if district_name == "BURNLEY"
replace district_outcome = 2 if district_name == "CHORLEY"
replace district_outcome = 1 if district_name == "FYLDE"
replace district_outcome = 2 if district_name == "HYNDBURN"
replace district_outcome = 1 if district_name == "ALDERSHOT"
replace district_outcome = 1 if district_name == "LANCASTER & WYRE"
replace district_outcome = 2 if district_name == "MORECAMBE & LUNESDALE"
replace district_outcome = 2 if district_name == "PENDLE"
replace district_outcome = 2 if district_name == "PRESTON"
replace district_outcome = 1 if district_name == "RIBBLE VALLEY"
replace district_outcome = 2 if district_name == "ROSSENDALE & DARWEN"
replace district_outcome = 2 if district_name == "SOUTH RIBBLE"
replace district_outcome = 2 if district_name == "WEST LANCASHIRE"
replace district_outcome = 2 if district_name == "BIRKENHEAD"
replace district_outcome = 2 if district_name == "BOOTLE"
replace district_outcome = 1 if district_name == "BASINGSTOKE"
replace district_outcome = 2 if district_name == "CROSBY"
replace district_outcome = 2 if district_name == "KNOWSLEY NORTH & SEFTON EAST"
replace district_outcome = 2 if district_name == "KNOWSLEY SOUTH"
replace district_outcome = 2 if district_name == "LIVERPOOL, GARSTON"
replace district_outcome = 2 if district_name == "LIVERPOOL, RIVERSIDE"
replace district_outcome = 2 if district_name == "LIVERPOOL, WALTON"
replace district_outcome = 2 if district_name == "LIVERPOOL, WAVERTREE"
replace district_outcome = 2 if district_name == "LIVERPOOL, WEST DERBY"
replace district_outcome = 3 if district_name == "SOUTHPORT"
replace district_outcome = 2 if district_name == "ST HELENS NORTH"
replace district_outcome = 1 if district_name == "EAST HAMPSHIRE"
replace district_outcome = 2 if district_name == "ST HELENS SOUTH"
replace district_outcome = 2 if district_name == "WALLASEY"
replace district_outcome = 2 if district_name == "WIRRAL SOUTH"
replace district_outcome = 2 if district_name == "WIRRAL WEST"
replace district_outcome = 2 if district_name == "BARROW & FURNESS"
replace district_outcome = 2 if district_name == "CARLISLE"
replace district_outcome = 2 if district_name == "COPELAND"
replace district_outcome = 1 if district_name == "PENRITH & THE BORDER"
replace district_outcome = 3 if district_name == "WESTMORLAND & LONSDALE"
replace district_outcome = 2 if district_name == "WORKINGTON"
replace district_outcome = 1 if district_name == "BEDFORDSHIRE NORTH EAST"
replace district_outcome = 3 if district_name == "EASTLEIGH"
replace district_outcome = 2 if district_name == "HARTLEPOOL"
replace district_outcome = 2 if district_name == "MIDDLESBROUGH"
replace district_outcome = 2 if district_name == "MIDDLESBROUGH SOUTH & EAST CLEVELAND"
replace district_outcome = 2 if district_name == "REDCAR"
replace district_outcome = 2 if district_name == "STOCKTON NORTH"
replace district_outcome = 2 if district_name == "STOCKTON SOUTH"
replace district_outcome = 2 if district_name == "BISHOP AUCKLAND"
replace district_outcome = 2 if district_name == "DARLINGTON"
replace district_outcome = 2 if district_name == "DURHAM, CITY OF"
replace district_outcome = 2 if district_name == "EASINGTON"
replace district_outcome = 1 if district_name == "FAREHAM"
replace district_outcome = 2 if district_name == "NORTH DURHAM"
replace district_outcome = 2 if district_name == "NORTH WEST DURHAM"
replace district_outcome = 2 if district_name == "SEDGEFIELD"
replace district_outcome = 3 if district_name == "BERWICK-UPON-TWEED"
replace district_outcome = 2 if district_name == "BLYTH VALLEY"
replace district_outcome = 1 if district_name == "HEXHAM"
replace district_outcome = 2 if district_name == "WANSBECK"
replace district_outcome = 2 if district_name == "BLAYDON"
replace district_outcome = 2 if district_name == "GATESHEAD EAST & WASHINGTON WEST"
replace district_outcome = 2 if district_name == "HOUGHTON & WASHINGTON EAST"
replace district_outcome = 1 if district_name == "GOSPORT"
replace district_outcome = 2 if district_name == "JARROW"
replace district_outcome = 2 if district_name == "NEWCASTLE UPON TYNE CENTRAL"
replace district_outcome = 2 if district_name == "NEWCASTLE UPON TYNE NORTH"
replace district_outcome = 2 if district_name == "NEWCASTLE UPON TYNE EAST & WALLSEND"
replace district_outcome = 2 if district_name == "NORTH TYNESIDE"
replace district_outcome = 2 if district_name == "SOUTH SHIELDS"
replace district_outcome = 2 if district_name == "SUNDERLAND NORTH"
replace district_outcome = 2 if district_name == "SUNDERLAND SOUTH"
replace district_outcome = 2 if district_name == "TYNE BRIDGE"
replace district_outcome = 2 if district_name == "TYNEMOUTH"
replace district_outcome = 1 if district_name == "HAVANT"
replace district_outcome = 2 if district_name == "ALYN & DEESIDE"
replace district_outcome = 2 if district_name == "CLWYD SOUTH"
replace district_outcome = 1 if district_name == "CLWYD WEST"
replace district_outcome = 2 if district_name == "DELYN"
replace district_outcome = 2 if district_name == "VALE OF CLWYD"
replace district_outcome = 2 if district_name == "WREXHAM"
replace district_outcome = 7 if district_name == "CARMARTHEN EAST & DINEFWR"
replace district_outcome = 2 if district_name == "CARMARTHEN WEST & SOUTH PEMBROKESHIRE"
replace district_outcome = 3 if district_name == "CEREDIGION"
replace district_outcome = 2 if district_name == "LLANELLI"
replace district_outcome = 1 if district_name == "NEW FOREST EAST"
replace district_outcome = 1 if district_name == "PRESELI PEMBROKESHIRE"
replace district_outcome = 9 if district_name == "BLAENAU GWENT"
replace district_outcome = 2 if district_name == "ISLWYN"
replace district_outcome = 1 if district_name == "MONMOUTH"
replace district_outcome = 2 if district_name == "NEWPORT EAST"
replace district_outcome = 2 if district_name == "NEWPORT WEST"
replace district_outcome = 2 if district_name == "TORFAEN"
replace district_outcome = 7 if district_name == "CAERNARFON"
replace district_outcome = 2 if district_name == "CONWY"
replace district_outcome = 7 if district_name == "MEIRIONNYDD NANT CONWY"
replace district_outcome = 1 if district_name == "NEW FOREST WEST"
replace district_outcome = 2 if district_name == "YNYS-MON"
replace district_outcome = 2 if district_name == "BRIDGEND"
replace district_outcome = 2 if district_name == "CAERPHILLY"
replace district_outcome = 2 if district_name == "CYNON VALLEY"
replace district_outcome = 2 if district_name == "MERTHYR TYDFIL & RHYMNEY"
replace district_outcome = 2 if district_name == "OGMORE"
replace district_outcome = 2 if district_name == "PONTYPRIDD"
replace district_outcome = 2 if district_name == "RHONDDA"
replace district_outcome = 3 if district_name == "BRECON & RADNORSHIRE"
replace district_outcome = 3 if district_name == "MONTGOMERYSHIRE"
replace district_outcome = 1 if district_name == "NORTH EAST HAMPSHIRE"
replace district_outcome = 3 if district_name == "CARDIFF CENTRAL"
replace district_outcome = 2 if district_name == "CARDIFF NORTH"
replace district_outcome = 2 if district_name == "CARDIFF SOUTH & PENARTH"
replace district_outcome = 2 if district_name == "CARDIFF WEST"
replace district_outcome = 2 if district_name == "VALE OF GLAMORGAN"
replace district_outcome = 2 if district_name == "ABERAVON"
replace district_outcome = 2 if district_name == "GOWER"
replace district_outcome = 2 if district_name == "NEATH"
replace district_outcome = 2 if district_name == "SWANSEA EAST"
replace district_outcome = 2 if district_name == "SWANSEA WEST"
replace district_outcome = 1 if district_name == "NORTH WEST HAMPSHIRE"
replace district_outcome = 2 if district_name == "PORTSMOUTH NORTH"
replace district_outcome = 3 if district_name == "PORTSMOUTH SOUTH"
replace district_outcome = 1 if district_name == "SOUTH WEST BEDFORDSHIRE"
replace district_outcome = 3 if district_name == "ROMSEY"
replace district_outcome = 2 if district_name == "SOUTHAMPTON, ITCHEN"
replace district_outcome = 2 if district_name == "SOUTHAMPTON, TEST"
replace district_outcome = 3 if district_name == "WINCHESTER"
replace district_outcome = 1 if district_name == "BROXBOURNE"
replace district_outcome = 9 if district_name == "BELFAST EAST"
replace district_outcome = 9 if district_name == "BELFAST NORTH"
replace district_outcome = 9 if district_name == "BELFAST SOUTH"
replace district_outcome = 5 if district_name == "BELFAST WEST"
replace district_outcome = 9 if district_name == "EAST ANTRIM"
replace district_outcome = 9 if district_name == "EAST LONDONDERRY"
replace district_outcome = 5 if district_name == "FERMANAGH & SOUTH TYRONE"
replace district_outcome = 9 if district_name == "FOYLE"
replace district_outcome = 1 if district_name == "HEMEL HEMPSTEAD"
replace district_outcome = 9 if district_name == "LAGAN VALLEY"
replace district_outcome = 5 if district_name == "MID ULSTER"
replace district_outcome = 5 if district_name == "NEWRY & ARMAGH"
replace district_outcome = 9 if district_name == "NORTH ANTRIM"
replace district_outcome = 9 if district_name == "NORTH DOWN"
replace district_outcome = 9 if district_name == "SOUTH ANTRIM"
replace district_outcome = 9 if district_name == "SOUTH DOWN"
replace district_outcome = 9 if district_name == "STRANGFORD"
replace district_outcome = 9 if district_name == "UPPER BANN"
replace district_outcome = 5 if district_name == "WEST TYRONE"
replace district_outcome = 1 if district_name == "HERTFORD & STORTFORD"
replace district_outcome = 1 if district_name == "HERTSMERE"
replace district_outcome = 1 if district_name == "HITCHIN & HARPENDEN"
replace district_outcome = 1 if district_name == "HERTFORDSHIRE NORTH EAST"
replace district_outcome = 1 if district_name == "BRACKNELL"
replace district_outcome = 1 if district_name == "SOUTH WEST HERTFORDSHIRE"
replace district_outcome = 1 if district_name == "ST ALBANS"
replace district_outcome = 2 if district_name == "STEVENAGE"
replace district_outcome = 2 if district_name == "WATFORD"
replace district_outcome = 1 if district_name == "WELWYN HATFIELD"
replace district_outcome = 1 if district_name == "ISLE OF WIGHT"
replace district_outcome = 1 if district_name == "ASHFORD"
replace district_outcome = 1 if district_name == "CANTERBURY"
replace district_outcome = 2 if district_name == "CHATHAM & AYLESFORD"
replace district_outcome = 2 if district_name == "DARTFORD"
replace district_outcome = 1 if district_name == "MAIDENHEAD"
replace district_outcome = 2 if district_name == "DOVER"
replace district_outcome = 1 if district_name == "FAVERSHAM & MID KENT"
replace district_outcome = 1 if district_name == "FOLKESTONE & HYTHE"
replace district_outcome = 2 if district_name == "GILLINGHAM"
replace district_outcome = 1 if district_name == "GRAVESHAM"
replace district_outcome = 1 if district_name == "MAIDSTONE & THE WEALD"
replace district_outcome = 2 if district_name == "MEDWAY"
replace district_outcome = 1 if district_name == "NORTH THANET"
replace district_outcome = 1 if district_name == "SEVENOAKS"
replace district_outcome = 2 if district_name == "SITTINGBOURNE & SHEPPEY"
replace district_outcome = 1 if district_name == "NEWBURY"
replace district_outcome = 2 if district_name == "SOUTH THANET"
replace district_outcome = 1 if district_name == "TONBRIDGE & MALLING"
replace district_outcome = 1 if district_name == "TUNBRIDGE WELLS"
replace district_outcome = 1 if district_name == "BANBURY"
replace district_outcome = 1 if district_name == "HENLEY"
replace district_outcome = 2 if district_name == "OXFORD EAST"
replace district_outcome = 3 if district_name == "OXFORD WEST & ABINGDON"
replace district_outcome = 1 if district_name == "WANTAGE"
replace district_outcome = 1 if district_name == "WITNEY"
replace district_outcome = 1 if district_name == "EAST SURREY"
replace district_outcome = 2 if district_name == "ABERDEEN NORTH"
replace district_outcome = 2 if district_name == "ABERDEEN SOUTH"
replace district_outcome = 2 if district_name == "AIRDRIE & SHOTTS"
replace district_outcome = 6 if district_name == "ANGUS"
replace district_outcome = 3 if district_name == "ARGYLL & BUTE"
replace district_outcome = 2 if district_name == "AYR, CARRICK & CUMNOCK"
replace district_outcome = 6 if district_name == "BANFF & BUCHAN"
replace district_outcome = 3 if district_name == "BERWICKSHIRE, ROXBURGH & SELKIRK"
replace district_outcome = 3 if district_name == "CAITHNESS, SUTHERLAND & EASTER ROSS"
replace district_outcome = 2 if district_name == "AYRSHIRE CENTRAL"
replace district_outcome = 2 if district_name == "COATBRIDGE, CHRYSTON & BELLSHILL"
replace district_outcome = 2 if district_name == "CUMBERNAULD, KILSYTH & KIRKINTILLOCH EAST"
replace district_outcome = 2 if district_name == "DUMFRIES & GALLOWAY"
replace district_outcome = 1 if district_name == "DUMFRIESSHIRE, CLYDESDALE & TWEEDDALE"
replace district_outcome = 6 if district_name == "DUNDEE EAST"
replace district_outcome = 2 if district_name == "DUNDEE WEST"
replace district_outcome = 2 if district_name == "DUNFERMLINE & WEST FIFE"
replace district_outcome = 3 if district_name == "DUNBARTONSHIRE EAST"
replace district_outcome = 2 if district_name == "EAST KILBRIDE, STRATHAVEN & LESMAHAGOW"
replace district_outcome = 2 if district_name == "EAST LOTHIAN"
replace district_outcome = 2 if district_name == "EAST RENFREWSHIRE"
replace district_outcome = 2 if district_name == "EDINBURGH EAST"
replace district_outcome = 2 if district_name == "EDINBURGH NORTH & LEITH"
replace district_outcome = 2 if district_name == "EDINBURGH SOUTH"
replace district_outcome = 2 if district_name == "EDINBURGH SOUTH WEST"
replace district_outcome = 3 if district_name == "EDINBURGH WEST"
replace district_outcome = 6 if district_name == "NA H-EILEANAN AN IAR"
replace district_outcome = 2 if district_name == "FALKIRK"
replace district_outcome = 2 if district_name == "GLASGOW CENTRAL"
replace district_outcome = 2 if district_name == "GLASGOW EAST"
replace district_outcome = 2 if district_name == "GLASGOW NORTH"
replace district_outcome = 9 if district_name == "GLASGOW NORTH EAST"
replace district_outcome = 2 if district_name == "GLASGOW NORTH WEST"
replace district_outcome = 2 if district_name == "GLASGOW SOUTH"
replace district_outcome = 2 if district_name == "GLASGOW SOUTH WEST"
replace district_outcome = 2 if district_name == "GLENROTHES"
replace district_outcome = 3 if district_name == "GORDON"
replace district_outcome = 2 if district_name == "INVERCLYDE"
replace district_outcome = 3 if district_name == "INVERNESS, NAIRN, BADENOCH & STRATHSPEY"
replace district_outcome = 2 if district_name == "KILMARNOCK & LOUDOUN"
replace district_outcome = 2 if district_name == "KIRKCALDY & COWDENBEATH"
replace district_outcome = 2 if district_name == "LANARCK & HAMILTON EAST"
replace district_outcome = 2 if district_name == "LINLITHGOW & EAST FALKIRK"
replace district_outcome = 2 if district_name == "LIVINGSTONE"
replace district_outcome = 2 if district_name == "MIDLOTHIAN"
replace district_outcome = 6 if district_name == "MORAY"
replace district_outcome = 2 if district_name == "MOTHERWELL & WISHAW"
replace district_outcome = 2 if district_name == "NORTH AYRSHIRE & ARRAN"
replace district_outcome = 3 if district_name == "NORTH EAST FIFE"
replace district_outcome = 2 if district_name == "OCHIL & SOUTH PERTHSHIRE"
replace district_outcome = 3 if district_name == "ORKNEY & SHETLAND"
replace district_outcome = 2 if district_name == "PAISLEY & RENFREWSHIRE NORTH"
replace district_outcome = 2 if district_name == "PAISLEY & RENFREWSHIRE SOUTH"
replace district_outcome = 6 if district_name == "PERTH & NORTH PERTHSHIRE"
replace district_outcome = 3 if district_name == "ROSS, SKYE & LOCHABER"
replace district_outcome = 2 if district_name == "RUTHERGLEN & HAMILTON WEST"
replace district_outcome = 2 if district_name == "STIRLING"
replace district_outcome = 3 if district_name == "ABERDEENSHIRE WEST & KINCARDINE"
replace district_outcome = 2 if district_name == "DUNBARTONSHIRE WEST"


******************************************
** DISTRICT OUTCOMES (FROM THE DATASET) **
******************************************

* Note: Variable win05 indicates the seat winner in each constituency.

gen constituency_2005 = win05

recode constituency_2005 2=1 1=2 4=5 5=4 7=2

label define constituency 1 "Labour" 2 "Conservative" 3 "Liberal Democrat" 4 "SNP" 5 "PC"
label values constituency_2005 constituency


*********************
** COMPETITIVENESS **
*********************

* Margin of victory by district

gen margin = .

replace margin = 8.040977 if district_name == "BEDFORD"
replace margin = 1.081709 if district_name == "READING EAST"
replace margin = 32.9738 if district_name == "EPSOM & EWELL"
replace margin = 16.13894 if district_name == "ESHER & WALTON"
replace margin = .6720769 if district_name == "GUILDFORD"
replace margin = 24.27805 if district_name == "MOLE VALLEY"
replace margin = 25.7904 if district_name == "REIGATE"
replace margin = 28.37285 if district_name == "RUNNYMEDE & WEYBRIDGE"
replace margin = 10.89698 if district_name == "SURREY SOUTH WEST"
replace margin = 23.19923 if district_name == "SPELTHORNE"
replace margin = 22.66079 if district_name == "SURREY HEATH"
replace margin = 14.35987 if district_name == "WOKING"
replace margin = 11.12035 if district_name == "READING WEST"
replace margin = 22.75911 if district_name == "ARUNDEL & SOUTH DOWNS"
replace margin = 19.1965 if district_name == "BOGNOR REGIS & LITTLEHAMPTON"
replace margin = 20.72479 if district_name == "CHICHESTER"
replace margin = .0881519 if district_name == "CRAWLEY"
replace margin = 18.37101 if district_name == "EAST WORTHING & SHOREHAM"
replace margin = 23.17093 if district_name == "HORSHAM"
replace margin = 11.90043 if district_name == "MID SUSSEX"
replace margin = 20.86959 if district_name == "WORTHING WEST"
replace margin = 9.958916 if district_name == "CAMBRIDGE"
replace margin = 24.50876 if district_name == "HUNTINGDON"
replace margin = 21.16458 if district_name == "SLOUGH"
replace margin = 17.49514 if district_name == "NORTH EAST CAMBRIDGESHIRE"
replace margin = 20.02974 if district_name == "NORTH WEST CAMBRIDGESHIRE"
replace margin = 6.64984 if district_name == "PETERBOROUGH"
replace margin = 15.19716 if district_name == "SOUTH CAMBRIDGESHIRE"
replace margin = 15.38352 if district_name == "SOUTH EAST CAMBRIDGESHIRE"
replace margin = 7.383151 if district_name == "GREAT YARMOUTH"
replace margin = 13.81226 if district_name == "MID NORFOLK"
replace margin = 17.98694 if district_name == "NORTH NORFOLK"
replace margin = 18.12474 if district_name == "NORFOLK NORTH WEST"
replace margin = 11.60674 if district_name == "NORWICH NORTH"
replace margin = 23.55526 if district_name == "WINDSOR"
replace margin = 8.65845 if district_name == "NORWICH SOUTH"
replace margin = 14.89131 if district_name == "SOUTH NORFOLK"
replace margin = 18.29593 if district_name == "NORFOLK SOUTH WEST"
replace margin = 18.87151 if district_name == "BURY ST EDMUNDS"
replace margin = 15.4445 if district_name == "CENTRAL SUFFOLK & NORTH IPSWICH"
replace margin = 12.73222 if district_name == "IPSWICH"
replace margin = 13.56273 if district_name == "SOUTH SUFFOLK"
replace margin = 18.42761 if district_name == "SUFFOLK COASTAL"
replace margin = 11.91267 if district_name == "WAVENEY"
replace margin = 20.15383 if district_name == "WEST SUFFOLK"
replace margin = 15.71453 if district_name == "WOKINGHAM"
replace margin = 23.70645 if district_name == "BARKING"
replace margin = .3970864 if district_name == "BATTERSEA"
replace margin = 17.1575 if district_name == "BECKENHAM"
replace margin = 6.542141 if district_name == "BETHNAL GREEN & BOW"
replace margin = 10.68812 if district_name == "BEXLEYHEATH & CRAYFORD"
replace margin = 8.729239 if district_name == "BRENT EAST"
replace margin = 15.80909 if district_name == "BRENT NORTH"
replace margin = 38.05268 if district_name == "BRENT SOUTH"
replace margin = 9.585588 if district_name == "BRENTFORD & ISLEWORTH"
replace margin = 28.91822 if district_name == "BROMLEY & CHISLEHURST"
replace margin = 21.50602 if district_name == "AYLESBURY"
replace margin = 46.50754 if district_name == "CAMBERWELL & PECKHAM"
replace margin = 2.480202 if district_name == "CARSHALTON & WALLINGTON"
replace margin = 27.53312 if district_name == "CHINGFORD & WOODFORD GREEN"
replace margin = 14.06291 if district_name == "CHIPPING BARNET"
replace margin = 22.18598 if district_name == "CITIES OF LONDON & WESTMINSTER"
replace margin = .1531957 if district_name == "CROYDON CENTRAL"
replace margin = 31.67377 if district_name == "CROYDON NORTH"
replace margin = 27.66632 if district_name == "CROYDON SOUTH"
replace margin = 24.65873 if district_name == "DAGENHAM"
replace margin = 20.97454 if district_name == "DULWICH & WEST NORWOOD"
replace margin = 35.04584 if district_name == "BEACONSFIELD"
replace margin = 24.31714 if district_name == "EALING, SOUTHALL"
replace margin = 15.17836 if district_name == "EALING NORTH"
replace margin = 13.9313 if district_name == "EALING, ACTON & SHEPHERD'S BUSH"
replace margin = 31.77993 if district_name == "EAST HAM"
replace margin = 23.26888 if district_name == "EDMONTON"
replace margin = 9.279139 if district_name == "ELTHAM"
replace margin = 4.711772 if district_name == "ENFIELD NORTH"
replace margin = 4.13883 if district_name == "ENFIELD, SOUTHGATE"
replace margin = 30.54368 if district_name == "ERITH & THAMESMEAD"
replace margin = 18.29301 if district_name == "FELTHAM & HESTON"
replace margin = 37.52872 if district_name == "BUCKINGHAM"
replace margin = 1.714722 if district_name == "FINCHLEY & GOLDERS GREEN"
replace margin = 28.488 if district_name == "GREENWICH & WOOLWICH"
replace margin = 25.2791 if district_name == "HACKNEY NORTH & STOKE NEWINGTON"
replace margin = 31.65307 if district_name == "HACKNEY SOUTH & SHOREDITCH"
replace margin = 10.19523 if district_name == "HAMMERSMITH & FULHAM"
replace margin = 9.768684 if district_name == "HAMPSTEAD & HIGHGATE"
replace margin = 9.30681 if district_name == "HARROW EAST"
replace margin = 4.24632 if district_name == "HARROW WEST"
replace margin = 33.48977 if district_name == "HAYES & HARLINGTON"
replace margin = 6.450919 if district_name == "HENDON"
replace margin = 29.29698 if district_name == "CHESHAM & AMERSHAM"
replace margin = 13.9323 if district_name == "HOLBORN & ST PANCRAS"
replace margin = 1.257565 if district_name == "HORNCHURCH"
replace margin = 5.060215 if district_name == "HORNSEY & WOOD GREEN"
replace margin = 3.844186 if district_name == "ILFORD NORTH"
replace margin = 21.61478 if district_name == "ILFORD SOUTH"
replace margin = 21.3247 if district_name == "ISLINGTON NORTH"
replace margin = 1.563257 if district_name == "ISLINGTON SOUTH & FINSBURY"
replace margin = 39.62854 if district_name == "KENSINGTON & CHELSEA"
replace margin = 18.02211 if district_name == "KINGSTON & SURBITON"
replace margin = 21.68857 if district_name == "LEWISHAM EAST"
replace margin = 8.148916 if district_name == "MILTON KEYNES SOUTH WEST"
replace margin = 31.11236 if district_name == "LEWISHAM WEST"
replace margin = 38.86092 if district_name == "LEWISHAM, DEPTFORD"
replace margin = 20.60892 if district_name == "LEYTON & WANSTEAD"
replace margin = 31.50396 if district_name == "MITCHAM & MORDEN"
replace margin = 14.24168 if district_name == "SOUTHWARK NORTH & BERMONDSEY"
replace margin = 22.25612 if district_name == "OLD BEXLEY & SIDCUP"
replace margin = 9.038258 if district_name == "ORPINGTON"
replace margin = 15.80364 if district_name == "POPLAR & CANNING TOWN"
replace margin = 4.828567 if district_name == "PUTNEY"
replace margin = 15.07129 if district_name == "REGENT'S PARK & KENSINGTON NORTH"
replace margin = 16.58146 if district_name == "LUTON NORTH"
replace margin = 3.323088 if district_name == "NORTH EAST MILTON KEYNES"
replace margin = 7.262428 if district_name == "RICHMOND PARK"
replace margin = 31.76635 if district_name == "ROMFORD"
replace margin = 22.4603 if district_name == "RUISLIP - NORTHWOOD"
replace margin = 18.38237 if district_name == "STREATHAM"
replace margin = 6.787179 if district_name == "SUTTON & CHEAM"
replace margin = 12.94505 if district_name == "TOOTING"
replace margin = 41.16347 if district_name == "TOTTENHAM"
replace margin = 19.27951 if district_name == "TWICKENHAM"
replace margin = 17.42415 if district_name == "UPMINSTER"
replace margin = 17.95043 if district_name == "UXBRIDGE"
replace margin = 15.87098 if district_name == "WYCOMBE"
replace margin = 26.71004 if district_name == "VAUXHALL"
replace margin = 23.20578 if district_name == "WALTHAMSTOW"
replace margin = 24.85307 if district_name == "WEST HAM"
replace margin = 5.301355 if district_name == "WIMBLEDON"
replace margin = 10.11868 if district_name == "BATH"
replace margin = 20.66395 if district_name == "BRISTOL EAST"
replace margin = 18.87055 if district_name == "BRISTOL NORTH WEST"
replace margin = 26.323 if district_name == "BRISTOL SOUTH"
replace margin = 8.934421 if district_name == "BRISTOL WEST"
replace margin = 13.98128 if district_name == "KINGSWOOD"
replace margin = 28.71632 if district_name == "BEXHILL & BATTLE"
replace margin = 18.68227 if district_name == "NORTHAVON"
replace margin = 3.610626 if district_name == "WANSDYKE"
replace margin = 4.234647 if district_name == "WESTON-SUPER-MARE"
replace margin = 11.65485 if district_name == "WOODSPRING"
replace margin = 3.927939 if district_name == "FALMOUTH & CAMBORNE"
replace margin = 5.494623 if district_name == "CORNWALL NORTH"
replace margin = 12.17286 if district_name == "SOUTH EAST CORNWALL"
replace margin = 23.02596 if district_name == "ST IVES"
replace margin = 14.35692 if district_name == "TRURO & ST AUSTELL"
replace margin = 16.11469 if district_name == "EAST DEVON"
replace margin = 6.890909 if district_name == "BRIGHTON, KEMPTOWN"
replace margin = 13.91915 if district_name == "EXETER"
replace margin = 9.574427 if district_name == "NORTH DEVON"
replace margin = 19.28689 if district_name == "PLYMOUTH, DEVONPORT"
replace margin = 10.7588 if district_name == "PLYMOUTH, SUTTON"
replace margin = 20.7446 if district_name == "SOUTH WEST DEVON"
replace margin = 10.20559 if district_name == "TEIGNBRIDGE"
replace margin = 18.99842 if district_name == "TIVERTON & HONITON"
replace margin = 4.289369 if district_name == "TORBAY"
replace margin = 5.523693 if district_name == "TORRIDGE & WEST DEVON"
replace margin = 3.849728 if district_name == "TOTNES"
replace margin = 11.22034 if district_name == "BRIGHTON, PAVILION"
replace margin = 13.94718 if district_name == "BOURNEMOUTH EAST"
replace margin = 11.88244 if district_name == "BOURNEMOUTH WEST"
replace margin = 30.17357 if district_name == "CHRISTCHURCH"
replace margin = 12.13933 if district_name == "MID DORSET & NORTH POOLE"
replace margin = 4.248793 if district_name == "NORTH DORSET"
replace margin = 14.78044 if district_name == "POOLE"
replace margin = 3.729623 if district_name == "SOUTH DORSET"
replace margin = 4.623767 if district_name == "DORSET WEST"
replace margin = 5.279567 if district_name == "CHELTENHAM"
replace margin = 20.45997 if district_name == "COTSWOLD"
replace margin = 2.322698 if district_name == "EASTBOURNE"
replace margin = 4.301008 if district_name == "FOREST OF DEAN"
replace margin = 8.244697 if district_name == "GLOUCESTER"
replace margin = .6153846 if district_name == "STROUD"
replace margin = 21.76314 if district_name == "TEWKESBURY"
replace margin = 17.60378 if district_name == "BRIDGWATER"
replace margin = 1.500869 if district_name == "SOMERTON & FROME"
replace margin = .9625722 if district_name == "TAUNTON"
replace margin = 5.739639 if district_name == "WELLS"
replace margin = 17.15385 if district_name == "YEOVIL"
replace margin = 23.49945 if district_name == "DEVIZES"
replace margin = 4.71119 if district_name == "HASTINGS & RYE"
replace margin = 5.727972 if district_name == "SWINDON NORTH"
replace margin = 9.459339 if district_name == "NORTH WILTSHIRE"
replace margin = 20.51103 if district_name == "SALISBURY"
replace margin = 3.112348 if district_name == "SOUTH SWINDON"
replace margin = 9.619811 if district_name == "WESTBURY"
replace margin = 21.08346 if district_name == "BROMSGROVE"
replace margin = 2.051435 if district_name == "HEREFORD"
replace margin = 27.02642 if district_name == "LEOMINSTER"
replace margin = 27.69132 if district_name == "MID WORCESTERSHIRE"
replace margin = 6.74096 if district_name == "REDDITCH"
replace margin = .9375837 if district_name == "HOVE"
replace margin = 5.257344 if district_name == "WEST WORCESTERSHIRE"
replace margin = 6.777615 if district_name == "WORCESTER"
replace margin = 19.77781 if district_name == "WYRE FOREST"
replace margin = 4.355393 if district_name == "LUDLOW"
replace margin = 23.69383 if district_name == "NORTH SHROPSHIRE"
replace margin = 3.594719 if district_name == "SHREWSBURY & ATCHAM"
replace margin = 15.80424 if district_name == "TELFORD"
replace margin = 2.090824 if district_name == "WREKIN, THE"
replace margin = 2.967712 if district_name == "BURTON"
replace margin = 21.38107 if district_name == "CANNOCK CHASE"
replace margin = 18.2033 if district_name == "LEWES"
replace margin = 16.18508 if district_name == "LICHFIELD"
replace margin = 20.378 if district_name == "NEWCASTLE-UNDER-LYME"
replace margin = 34.51141 if district_name == "SOUTH STAFFORDSHIRE"
replace margin = 4.656013 if district_name == "STAFFORD"
replace margin = 5.509231 if district_name == "STAFFORDSHIRE MOORLANDS"
replace margin = 35.02347 if district_name == "STOKE-ON-TRENT CENTRAL"
replace margin = 32.62679 if district_name == "STOKE-ON-TRENT NORTH"
replace margin = 22.95346 if district_name == "STOKE-ON-TRENT SOUTH"
replace margin = 19.3235 if district_name == "STONE"
replace margin = 5.873343 if district_name == "TAMWORTH"
replace margin = 28.60762 if district_name == "WEALDEN"
replace margin = 16.0911 if district_name == "NORTH WARWICKSHIRE"
replace margin = 5.035336 if district_name == "NUNEATON"
replace margin = 2.862317 if district_name == "RUGBY & KENILWORTH"
replace margin = 20.92033 if district_name == "STRATFORD ON AVON"
replace margin = .4855432 if district_name == "WARWICK & LEAMINGTON"
replace margin = 13.92203 if district_name == "ALDRIDGE - BROWNHILLS"
replace margin = 6.242194 if district_name == "BIRMINGHAM, EDGBASTON"
replace margin = 30.16128 if district_name == "BIRMINGHAM, ERDINGTON"
replace margin = 16.54506 if district_name == "BIRMINGHAM, HALL GREEN"
replace margin = 19.17514 if district_name == "BIRMINGHAM, HODGE HILL"
replace margin = 14.5177 if district_name == "LUTON SOUTH"
replace margin = 7.283095 if district_name == "BASILDON"
replace margin = 20.4566 if district_name == "BIRMINGHAM, LADYWOOD"
replace margin = 20.78181 if district_name == "BIRMINGHAM, NORTHFIELD"
replace margin = 20.4261 if district_name == "BIRMINGHAM, PERRY BARR"
replace margin = 21.20508 if district_name == "BIRMINGHAM, SELLY OAK"
replace margin = 1.542208 if district_name == "BIRMINGHAM, SPARKBROOK & SMALL HEATH"
replace margin = 9.078862 if district_name == "BIRMINGHAM, YARDLEY"
replace margin = 38.23632 if district_name == "COVENTRY NORTH EAST"
replace margin = 21.44436 if district_name == "COVENTRY NORTH WEST"
replace margin = 15.37422 if district_name == "COVENTRY SOUTH"
replace margin = 13.11824 if district_name == "DUDLEY NORTH"
replace margin = 22.93586 if district_name == "BILLERICAY"
replace margin = 10.80558 if district_name == "DUDLEY SOUTH"
replace margin = 10.49435 if district_name == "HALESOWEN & ROWLEY REGIS"
replace margin = 15.07215 if district_name == "MERIDEN"
replace margin = .5333282 if district_name == "SOLIHULL"
replace margin = .975832 if district_name == "STOURBRIDGE"
replace margin = 26.51885 if district_name == "SUTTON COLDFIELD"
replace margin = 19.86359 if district_name == "WALSALL NORTH"
replace margin = 22.50035 if district_name == "WALSALL SOUTH"
replace margin = 31.6234 if district_name == "WARLEY"
replace margin = 32.81144 if district_name == "WEST BROMWICH EAST"
replace margin = 7.337668 if district_name == "BRAINTREE"
replace margin = 31.1997 if district_name == "WEST BROMWICH WEST"
replace margin = 24.74815 if district_name == "WOLVERHAMPTON NORTH EAST"
replace margin = 37.14913 if district_name == "WOLVERHAMPTON SOUTH EAST"
replace margin = 6.907556 if district_name == "WOLVERHAMPTON SOUTH WEST"
replace margin = 11.13081 if district_name == "AMBER VALLEY"
replace margin = 47.64206 if district_name == "BOLSOVER"
replace margin = 6.901475 if district_name == "CHESTERFIELD"
replace margin = 8.574102 if district_name == "DERBY NORTH"
replace margin = 13.04268 if district_name == "DERBY SOUTH"
replace margin = 14.01302 if district_name == "EREWASH"
replace margin = 26.30422 if district_name == "BRENTWOOD & ONGAR"
replace margin = 1.470323 if district_name == "HIGH PEAK"
replace margin = 23.17309 if district_name == "NORTH EAST DERBYSHIRE"
replace margin = 8.05267 if district_name == "SOUTH DERBYSHIRE"
replace margin = 21.02536 if district_name == "WEST DERBYSHIRE"
replace margin = 15.94112 if district_name == "BLABY"
replace margin = 11.19813 if district_name == "BOSWORTH"
replace margin = 17.40359 if district_name == "CHARNWOOD"
replace margin = 8.121531 if district_name == "HARBOROUGH"
replace margin = 38.43509 if district_name == "LEICESTER EAST"
replace margin = 8.764235 if district_name == "LEICESTER SOUTH"
replace margin = 17.90533 if district_name == "CASTLE POINT"
replace margin = 27.29954 if district_name == "LEICESTER WEST"
replace margin = 4.325964 if district_name == "LOUGHBOROUGH"
replace margin = 9.497242 if district_name == "NORTH WEST LEICESTERSHIRE"
replace margin = 26.23569 if district_name == "RUTLAND & MELTON"
replace margin = 14.10829 if district_name == "BOSTON & SKEGNESS"
replace margin = 17.51932 if district_name == "GAINSBOROUGH"
replace margin = 15.79104 if district_name == "GRANTHAM & STAMFORD"
replace margin = 12.51865 if district_name == "LINCOLN"
replace margin = 21.1983 if district_name == "LOUTH & HORNCASTLE"
replace margin = 23.79347 if district_name == "SLEAFORD & NORTH HYKEHAM"
replace margin = 13.98027 if district_name == "COLCHESTER"
replace margin = 32.70534 if district_name == "SOUTH HOLLAND & THE DEEPINGS"
replace margin = 3.178494 if district_name == "CORBY"
replace margin = 24.29888 if district_name == "DAVENTRY"
replace margin = 5.932142 if district_name == "KETTERING"
replace margin = 9.417809 if district_name == "NORTHAMPTON NORTH"
replace margin = 8.111085 if district_name == "NORTHAMPTON SOUTH"
replace margin = 1.296104 if district_name == "WELLINGBOROUGH"
replace margin = 24.28717 if district_name == "ASHFIELD"
replace margin = 26.86282 if district_name == "BASSETLAW"
replace margin = 4.70434 if district_name == "BROXTOWE"
replace margin = 32.00624 if district_name == "EPPING FOREST"
replace margin = 8.647802 if district_name == "GEDLING"
replace margin = 28.41206 if district_name == "MANSFIELD"
replace margin = 14.14566 if district_name == "NEWARK"
replace margin = 23.06005 if district_name == "NOTTINGHAM EAST"
replace margin = 40.05859 if district_name == "NOTTINGHAM NORTH"
replace margin = 21.4868 if district_name == "NOTTINGHAM SOUTH"
replace margin = 23.0399 if district_name == "RUSHCLIFFE"
replace margin = 14.11805 if district_name == "SHERWOOD"
replace margin = 5.139237 if district_name == "BEVERLEY & HOLDERNESS"
replace margin = 6.796937 if district_name == "BRIGG & GOOLE"
replace margin = .2441296 if district_name == "HARLOW"
replace margin = 6.061162 if district_name == "CLEETHORPES"
replace margin = 13.38945 if district_name == "EAST YORKSHIRE"
replace margin = 23.21927 if district_name == "GREAT GRIMSBY"
replace margin = 10.6519 if district_name == "HALTEMPRICE & HOWDEN"
replace margin = 37.745 if district_name == "KINGSTON UPON HULL EAST"
replace margin = 24.84789 if district_name == "KINGSTON UPON HULL NORTH"
replace margin = 33.97081 if district_name == "KINGSTON UPON HULL WEST & HESSLE"
replace margin = 27.43999 if district_name == "SCUNTHORPE"
replace margin = 24.33385 if district_name == "HARROGATE & KNARESBOROUGH"
replace margin = 39.39602 if district_name == "RICHMOND (YORKS)"
replace margin = 1.825107 if district_name == "HARWICH"
replace margin = 23.72847 if district_name == "RYEDALE"
replace margin = 2.653905 if district_name == "SCARBOROUGH & WHITBY"
replace margin = .8886943 if district_name == "SELBY"
replace margin = 23.00034 if district_name == "SKIPTON & RIPON"
replace margin = 27.21823 if district_name == "VALE OF YORK"
replace margin = 22.47355 if district_name == "YORK, CITY OF"
replace margin = 44.49415 if district_name == "BARNSLEY CENTRAL"
replace margin = 42.76933 if district_name == "BARNSLEY EAST & MEXBOROUGH"
replace margin = 30.70118 if district_name == "BARNSLEY WEST & PENISTONE"
replace margin = 23.32357 if district_name == "DON VALLEY"
replace margin = 27.27864 if district_name == "MALDON & EAST CHELMSFORD"
replace margin = 28.53483 if district_name == "DONCASTER CENTRAL"
replace margin = 38.50465 if district_name == "DONCASTER NORTH"
replace margin = 36.01469 if district_name == "ROTHER VALLEY"
replace margin = 35.62946 if district_name == "ROTHERHAM"
replace margin = 43.1319 if district_name == "SHEFFIELD, ATTERCLIFFE"
replace margin = 55.39811 if district_name == "SHEFFIELD, BRIGHTSIDE"
replace margin = 23.52843 if district_name == "SHEFFIELD CENTRAL"
replace margin = 21.47575 if district_name == "SHEFFIELD, HALLAM"
replace margin = 33.34995 if district_name == "SHEFFIELD, HEELEY"
replace margin = 24.5031 if district_name == "SHEFFIELD, HILLSBOROUGH"
replace margin = 22.52082 if district_name == "MID BEDFORDSHIRE"
replace margin = 22.734 if district_name == "NORTH ESSEX"
replace margin = 42.29689 if district_name == "WENTWORTH"
replace margin = 14.76229 if district_name == "BATLEY & SPEN"
replace margin = 10.20729 if district_name == "BRADFORD NORTH"
replace margin = 25.04303 if district_name == "BRADFORD SOUTH"
replace margin = 8.320272 if district_name == "BRADFORD WEST"
replace margin = 2.861629 if district_name == "CALDER VALLEY"
replace margin = 3.068275 if district_name == "COLNE VALLEY"
replace margin = 11.95751 if district_name == "DEWSBURY"
replace margin = 9.604208 if district_name == "ELMET"
replace margin = 8.615951 if district_name == "HALIFAX"
replace margin = 31.87929 if district_name == "RAYLEIGH"
replace margin = 36.64112 if district_name == "HEMSWORTH"
replace margin = 23.90097 if district_name == "HUDDERSFIELD"
replace margin = 10.47677 if district_name == "KEIGHLEY"
replace margin = 40.65648 if district_name == "LEEDS CENTRAL"
replace margin = 38.49453 if district_name == "LEEDS EAST"
replace margin = 12.68961 if district_name == "LEEDS NORTH EAST"
replace margin = 4.198072 if district_name == "LEEDS NORTH WEST"
replace margin = 37.99045 if district_name == "LEEDS WEST"
replace margin = 29.04577 if district_name == "MORLEY & ROTHWELL"
replace margin = 26.72617 if district_name == "NORMANTON"
replace margin = 13.91071 if district_name == "ROCHFORD & SOUTHEND EAST"
replace margin = 46.27432 if district_name == "PONTEFRACT & CASTLEFORD"
replace margin = 12.63888 if district_name == "PUDSEY"
replace margin = .885327 if district_name == "SHIPLEY"
replace margin = 11.88078 if district_name == "WAKEFIELD"
replace margin = 2.037726 if district_name == "CHESTER, CITY OF"
replace margin = 17.6642 if district_name == "CONGLETON"
replace margin = 16.27688 if district_name == "CREWE & NANTWICH"
replace margin = 13.56352 if district_name == "EDDISBURY"
replace margin = 15.41753 if district_name == "ELLESMERE PORT & NESTON"
replace margin = 42.72884 if district_name == "HALTON"
replace margin = 24.53414 if district_name == "SAFFRON WALDEN"
replace margin = 20.60674 if district_name == "MACCLESFIELD"
replace margin = 28.32617 if district_name == "TATTON"
replace margin = 30.19447 if district_name == "WARRINGTON NORTH"
replace margin = 7.511165 if district_name == "WARRINGTON SOUTH"
replace margin = 17.38965 if district_name == "WEAVER VALE"
replace margin = 16.15662 if district_name == "ALTRINCHAM & SALE WEST"
replace margin = 37.74177 if district_name == "ASHTON-UNDER-LYNE"
replace margin = 11.11593 if district_name == "BOLTON NORTH EAST"
replace margin = 36.54003 if district_name == "BOLTON SOUTH EAST"
replace margin = 5.090891 if district_name == "BOLTON WEST"
replace margin = 22.4931 if district_name == "SOUTHEND WEST"
replace margin = 6.584307 if district_name == "BURY NORTH"
replace margin = 22.7614 if district_name == "BURY SOUTH"
replace margin = 8.474398 if district_name == "CHEADLE"
replace margin = 38.08476 if district_name == "DENTON & REDDISH"
replace margin = 37.20836 if district_name == "ECCLES"
replace margin = 19.80725 if district_name == "HAZEL GROVE"
replace margin = 28.37938 if district_name == "HEYWOOD & MIDDLETON"
replace margin = 47.33611 if district_name == "LEIGH"
replace margin = 49.30298 if district_name == "MAKERFIELD"
replace margin = 43.5903 if district_name == "MANCHESTER, BLACKLEY"
replace margin = 14.59077 if district_name == "THURROCK"
replace margin = 33.40623 if district_name == "MANCHESTER CENTRAL"
replace margin = 19.943 if district_name == "MANCHESTER, GORTON"
replace margin = 1.780661 if district_name == "MANCHESTER, WITHINGTON"
replace margin = 8.278184 if district_name == "OLDHAM EAST & SADDLEWORTH"
replace margin = 27.83132 if district_name == "OLDHAM WEST & ROYTON"
replace margin = 1.082378 if district_name == "ROCHDALE"
replace margin = 35.15487 if district_name == "SALFORD"
replace margin = 23.63935 if district_name == "STALYBRIDGE & HYDE"
replace margin = 25.61572 if district_name == "STOCKPORT"
replace margin = 20.60576 if district_name == "STRETFORD & URMSTON"
replace margin = 18.84353 if district_name == "WEST CHELMSFORD"
replace margin = 34.32814 if district_name == "WIGAN"
replace margin = 25.35592 if district_name == "WORSLEY"
replace margin = 29.92207 if district_name == "WYTHENSHAWE & SALE EAST"
replace margin = 19.158 if district_name == "BLACKBURN"
replace margin = 11.69323 if district_name == "BLACKPOOL NORTH & FLEETWOOD"
replace margin = 20.66142 if district_name == "BLACKPOOL SOUTH"
replace margin = 11.39471 if district_name == "BURNLEY"
replace margin = 15.3826 if district_name == "CHORLEY"
replace margin = 27.3764 if district_name == "FYLDE"
replace margin = 14.16259 if district_name == "HYNDBURN"
replace margin = 11.07995 if district_name == "ALDERSHOT"
replace margin = 8.011755 if district_name == "LANCASTER & WYRE"
replace margin = 11.4519 if district_name == "MORECAMBE & LUNESDALE"
replace margin = 5.30001 if district_name == "PENDLE"
replace margin = 27.60189 if district_name == "PRESTON"
replace margin = 28.47526 if district_name == "RIBBLE VALLEY"
replace margin = 8.272386 if district_name == "ROSSENDALE & DARWEN"
replace margin = 4.59683 if district_name == "SOUTH RIBBLE"
replace margin = 14.09802 if district_name == "WEST LANCASHIRE"
replace margin = 46.54862 if district_name == "BIRKENHEAD"
replace margin = 63.83967 if district_name == "BOOTLE"
replace margin = 9.72508 if district_name == "BASINGSTOKE"
replace margin = 16.13527 if district_name == "CROSBY"
replace margin = 43.90738 if district_name == "KNOWSLEY NORTH & SEFTON EAST"
replace margin = 48.53474 if district_name == "KNOWSLEY SOUTH"
replace margin = 20.56671 if district_name == "LIVERPOOL, GARSTON"
replace margin = 32.74662 if district_name == "LIVERPOOL, RIVERSIDE"
replace margin = 57.13211 if district_name == "LIVERPOOL, WALTON"
replace margin = 14.70814 if district_name == "LIVERPOOL, WAVERTREE"
replace margin = 46.93409 if district_name == "LIVERPOOL, WEST DERBY"
replace margin = 9.315308 if district_name == "SOUTHPORT"
replace margin = 35.55295 if district_name == "ST HELENS NORTH"
replace margin = 10.36715 if district_name == "EAST HAMPSHIRE"
replace margin = 26.24249 if district_name == "ST HELENS SOUTH"
replace margin = 24.83979 if district_name == "WALLASEY"
replace margin = 9.379408 if district_name == "WIRRAL SOUTH"
replace margin = 2.66049 if district_name == "WIRRAL WEST"
replace margin = 16.5429 if district_name == "BARROW & FURNESS"
replace margin = 16.0903 if district_name == "CARLISLE"
replace margin = 18.72204 if district_name == "COPELAND"
replace margin = 25.39141 if district_name == "PENRITH & THE BORDER"
replace margin = .537916 if district_name == "WESTMORLAND & LONSDALE"
replace margin = 17.35159 if district_name == "WORKINGTON"
replace margin = 24.747 if district_name == "BEDFORDSHIRE NORTH EAST"
replace margin = 1.141227 if district_name == "EASTLEIGH"
replace margin = 21.10283 if district_name == "HARTLEPOOL"
replace margin = 39.10081 if district_name == "MIDDLESBROUGH"
replace margin = 18.30831 if district_name == "MIDDLESBROUGH SOUTH & EAST CLEVELAND"
replace margin = 31.17779 if district_name == "REDCAR"
replace margin = 34.14132 if district_name == "STOCKTON NORTH"
replace margin = 13.66561 if district_name == "STOCKTON SOUTH"
replace margin = 26.35071 if district_name == "BISHOP AUCKLAND"
replace margin = 26.41414 if district_name == "DARLINGTON"
replace margin = 7.379858 if district_name == "DURHAM, CITY OF"
replace margin = 58.50259 if district_name == "EASINGTON"
replace margin = 24.09009 if district_name == "FAREHAM"
replace margin = 44.93988 if district_name == "NORTH DURHAM"
replace margin = 34.02516 if district_name == "NORTH WEST DURHAM"
replace margin = 44.07106 if district_name == "SEDGEFIELD"
replace margin = 23.91798 if district_name == "BERWICK-UPON-TWEED"
replace margin = 23.83641 if district_name == "BLYTH VALLEY"
replace margin = 12.0926 if district_name == "HEXHAM"
replace margin = 28.72618 if district_name == "WANSBECK"
replace margin = 13.66092 if district_name == "BLAYDON"
replace margin = 38.67255 if district_name == "GATESHEAD EAST & WASHINGTON WEST"
replace margin = 46.30484 if district_name == "HOUGHTON & WASHINGTON EAST"
replace margin = 13.31505 if district_name == "GOSPORT"
replace margin = 40.9206 if district_name == "JARROW"
replace margin = 11.08575 if district_name == "NEWCASTLE UPON TYNE CENTRAL"
replace margin = 18.26813 if district_name == "NEWCASTLE UPON TYNE NORTH"
replace margin = 23.88093 if district_name == "NEWCASTLE UPON TYNE EAST & WALLSEND"
replace margin = 40.70765 if district_name == "NORTH TYNESIDE"
replace margin = 40.76011 if district_name == "SOUTH SHIELDS"
replace margin = 34.56923 if district_name == "SUNDERLAND NORTH"
replace margin = 36.00873 if district_name == "SUNDERLAND SOUTH"
replace margin = 39.41932 if district_name == "TYNE BRIDGE"
replace margin = 9.666581 if district_name == "TYNEMOUTH"
replace margin = 15.73843 if district_name == "HAVANT"
replace margin = 23.60266 if district_name == "ALYN & DEESIDE"
replace margin = 19.27667 if district_name == "CLWYD SOUTH"
replace margin = .3734486 if district_name == "CLWYD WEST"
replace margin = 19.53888 if district_name == "DELYN"
replace margin = 14.44929 if district_name == "VALE OF CLWYD"
replace margin = 22.44199 if district_name == "WREXHAM"
replace margin = 17.54459 if district_name == "CARMARTHEN EAST & DINEFWR"
replace margin = 5.044503 if district_name == "CARMARTHEN WEST & SOUTH PEMBROKESHIRE"
replace margin = .6092303 if district_name == "CEREDIGION"
replace margin = 20.46741 if district_name == "LLANELLI"
replace margin = 14.48215 if district_name == "NEW FOREST EAST"
replace margin = 1.573069 if district_name == "PRESELI PEMBROKESHIRE"
replace margin = 26.41911 if district_name == "BLAENAU GWENT"
replace margin = 50.99627 if district_name == "ISLWYN"
replace margin = 9.916106 if district_name == "MONMOUTH"
replace margin = 21.48625 if district_name == "NEWPORT EAST"
replace margin = 15.27482 if district_name == "NEWPORT WEST"
replace margin = 41.11009 if district_name == "TORFAEN"
replace margin = 18.60424 if district_name == "CAERNARFON"
replace margin = 9.154114 if district_name == "CONWY"
replace margin = 32.04457 if district_name == "MEIRIONNYDD NANT CONWY"
replace margin = 37.52143 if district_name == "NEW FOREST WEST"
replace margin = 3.502341 if district_name == "YNYS-MON"
replace margin = 17.22972 if district_name == "BRIDGEND"
replace margin = 39.15216 if district_name == "CAERPHILLY"
replace margin = 49.75795 if district_name == "CYNON VALLEY"
replace margin = 46.48385 if district_name == "MERTHYR TYDFIL & RHYMNEY"
replace margin = 45.25728 if district_name == "OGMORE"
replace margin = 33.28203 if district_name == "PONTYPRIDD"
replace margin = 52.1446 if district_name == "RHONDDA"
replace margin = 10.18492 if district_name == "BRECON & RADNORSHIRE"
replace margin = 23.83294 if district_name == "MONTGOMERYSHIRE"
replace margin = 26.53795 if district_name == "NORTH EAST HAMPSHIRE"
replace margin = 15.47935 if district_name == "CARDIFF CENTRAL"
replace margin = 2.526455 if district_name == "CARDIFF NORTH"
replace margin = 25.02438 if district_name == "CARDIFF SOUTH & PENARTH"
replace margin = 23.63068 if district_name == "CARDIFF WEST"
replace margin = 3.820472 if district_name == "VALE OF GLAMORGAN"
replace margin = 46.29617 if district_name == "ABERAVON"
replace margin = 16.9516 if district_name == "GOWER"
replace margin = 35.48594 if district_name == "NEATH"
replace margin = 36.48246 if district_name == "SWANSEA EAST"
replace margin = 12.90274 if district_name == "SWANSEA WEST"
replace margin = 25.8734 if district_name == "NORTH WEST HAMPSHIRE"
replace margin = 3.019858 if district_name == "PORTSMOUTH NORTH"
replace margin = 8.327141 if district_name == "PORTSMOUTH SOUTH"
replace margin = 18.06653 if district_name == "SOUTH WEST BEDFORDSHIRE"
replace margin = .2484546 if district_name == "ROMSEY"
replace margin = 21.51995 if district_name == "SOUTHAMPTON, ITCHEN"
replace margin = 16.7963 if district_name == "SOUTHAMPTON, TEST"
replace margin = 12.12495 if district_name == "WINCHESTER"
replace margin = 28.32775 if district_name == "BROXBOURNE"
replace margin = 19.06198 if district_name == "BELFAST EAST"
replace margin = 16.98756 if district_name == "BELFAST NORTH"
replace margin = 3.856001 if district_name == "BELFAST SOUTH"
replace margin = 55.91258 if district_name == "BELFAST WEST"
replace margin = 22.99241 if district_name == "EAST ANTRIM"
replace margin = 21.76374 if district_name == "EAST LONDONDERRY"
replace margin = 9.390692 if district_name == "FERMANAGH & SOUTH TYRONE"
replace margin = 13.06102 if district_name == "FOYLE"
replace margin = 1.059268 if district_name == "HEMEL HEMPSTEAD"
replace margin = 33.16029 if district_name == "LAGAN VALLEY"
replace margin = 24.16237 if district_name == "MID ULSTER"
replace margin = 16.16498 if district_name == "NEWRY & ARMAGH"
replace margin = 39.11728 if district_name == "NORTH ANTRIM"
replace margin = 15.31124 if district_name == "NORTH DOWN"
replace margin = 9.083963 if district_name == "SOUTH ANTRIM"
replace margin = 18.97171 if district_name == "SOUTH DOWN"
replace margin = 35.23709 if district_name == "STRANGFORD"
replace margin = 11.92652 if district_name == "UPPER BANN"
replace margin = 11.50919 if district_name == "WEST TYRONE"
replace margin = 26.35636 if district_name == "HERTFORD & STORTFORD"
replace margin = 26.05703 if district_name == "HERTSMERE"
replace margin = 24.04246 if district_name == "HITCHIN & HARPENDEN"
replace margin = 19.28906 if district_name == "HERTFORDSHIRE NORTH EAST"
replace margin = 23.53493 if district_name == "BRACKNELL"
replace margin = 16.91623 if district_name == "SOUTH WEST HERTFORDSHIRE"
replace margin = 2.993709 if district_name == "ST ALBANS"
replace margin = 7.485572 if district_name == "STEVENAGE"
replace margin = 2.324169 if district_name == "WATFORD"
replace margin = 13.29725 if district_name == "WELWYN HATFIELD"
replace margin = 19.41565 if district_name == "ISLE OF WIGHT"
replace margin = 25.72894 if district_name == "ASHFORD"
replace margin = 15.69967 if district_name == "CANTERBURY"
replace margin = 5.541825 if district_name == "CHATHAM & AYLESFORD"
replace margin = 1.509224 if district_name == "DARTFORD"
replace margin = 13.58997 if district_name == "MAIDENHEAD"
replace margin = 10.31869 if district_name == "DOVER"
replace margin = 19.98808 if district_name == "FAVERSHAM & MID KENT"
replace margin = 24.08098 if district_name == "FOLKESTONE & HYTHE"
replace margin = .5623575 if district_name == "GILLINGHAM"
replace margin = 1.447575 if district_name == "GRAVESHAM"
replace margin = 30.47072 if district_name == "MAIDSTONE & THE WEALD"
replace margin = .5183365 if district_name == "MEDWAY"
replace margin = 17.45633 if district_name == "NORTH THANET"
replace margin = 29.95519 if district_name == "SEVENOAKS"
replace margin = .1936132 if district_name == "SITTINGBOURNE & SHEPPEY"
replace margin = 6.328535 if district_name == "NEWBURY"
replace margin = 1.610009 if district_name == "SOUTH THANET"
replace margin = 28.98639 if district_name == "TONBRIDGE & MALLING"
replace margin = 23.51113 if district_name == "TUNBRIDGE WELLS"
replace margin = 19.20867 if district_name == "BANBURY"
replace margin = 27.48995 if district_name == "HENLEY"
replace margin = 2.304379 if district_name == "OXFORD EAST"
replace margin = 14.60646 if district_name == "OXFORD WEST & ABINGDON"
replace margin = 15.43779 if district_name == "WANTAGE"
replace margin = 26.27856 if district_name == "WITNEY"
replace margin = 32.32494 if district_name == "EAST SURREY"
replace margin = 18.54834 if district_name == "ABERDEEN NORTH"
replace margin = 3.23875 if district_name == "ABERDEEN SOUTH"
replace margin = 42.47542 if district_name == "AIRDRIE & SHOTTS"
replace margin = 4.197143 if district_name == "ANGUS"
replace margin = 13.21822 if district_name == "ARGYLL & BUTE"
replace margin = 22.19188 if district_name == "AYR, CARRICK & CUMNOCK"
replace margin = 31.80621 if district_name == "BANFF & BUCHAN"
replace margin = 13.00123 if district_name == "BERWICKSHIRE, ROXBURGH & SELKIRK"
replace margin = 29.5268 if district_name == "CAITHNESS, SUTHERLAND & EASTER ROSS"
replace margin = 24.31247 if district_name == "AYRSHIRE CENTRAL"
replace margin = 50.90496 if district_name == "COATBRIDGE, CHRYSTON & BELLSHILL"
replace margin = 29.57941 if district_name == "CUMBERNAULD, KILSYTH & KIRKINTILLOCH EAST"
replace margin = 5.741683 if district_name == "DUMFRIES & GALLOWAY"
replace margin = 3.895463 if district_name == "DUMFRIESSHIRE, CLYDESDALE & TWEEDDALE"
replace margin = .9686394 if district_name == "DUNDEE EAST"
replace margin = 14.56303 if district_name == "DUNDEE WEST"
replace margin = 27.27273 if district_name == "DUNFERMLINE & WEST FIFE"
replace margin = 8.691464 if district_name == "DUNBARTONSHIRE EAST"
replace margin = 30.84449 if district_name == "EAST KILBRIDE, STRATHAVEN & LESMAHAGOW"
replace margin = 16.64628 if district_name == "EAST LOTHIAN"
replace margin = 14.04282 if district_name == "EAST RENFREWSHIRE"
replace margin = 15.61863 if district_name == "EDINBURGH EAST"
replace margin = 5.04925 if district_name == "EDINBURGH NORTH & LEITH"
replace margin = .9485222 if district_name == "EDINBURGH SOUTH"
replace margin = 16.48682 if district_name == "EDINBURGH SOUTH WEST"
replace margin = 30.04529 if district_name == "EDINBURGH WEST"
replace margin = 10.41486 if district_name == "NA H-EILEANAN AN IAR"
replace margin = 29.45355 if district_name == "FALKIRK"
replace margin = 30.42765 if district_name == "GLASGOW CENTRAL"
replace margin = 43.65687 if district_name == "GLASGOW EAST"
replace margin = 11.95516 if district_name == "GLASGOW NORTH"
replace margin = 64.67731 if district_name == "GLASGOW NORTH EAST"
replace margin = 29.63213 if district_name == "GLASGOW NORTH WEST"
replace margin = 28.18558 if district_name == "GLASGOW SOUTH"
replace margin = 44.85909 if district_name == "GLASGOW SOUTH WEST"
replace margin = 28.53931 if district_name == "GLENROTHES"
replace margin = 24.8121 if district_name == "GORDON"
replace margin = 31.19009 if district_name == "INVERCLYDE"
replace margin = 9.372952 if district_name == "INVERNESS, NAIRN, BADENOCH & STRATHSPEY"
replace margin = 19.60886 if district_name == "KILMARNOCK & LOUDOUN"
replace margin = 43.58312 if district_name == "KIRKCALDY & COWDENBEATH"
replace margin = 27.40829 if district_name == "LANARCK & HAMILTON EAST"
replace margin = 24.14797 if district_name == "LINLITHGOW & EAST FALKIRK"
replace margin = 29.53966 if district_name == "LIVINGSTONE"
replace margin = 19.26851 if district_name == "MIDLOTHIAN"
replace margin = 14.63151 if district_name == "MORAY"
replace margin = 41.0197 if district_name == "MOTHERWELL & WISHAW"
replace margin = 25.55367 if district_name == "NORTH AYRSHIRE & ARRAN"
replace margin = 32.60452 if district_name == "NORTH EAST FIFE"
replace margin = 1.473328 if district_name == "OCHIL & SOUTH PERTHSHIRE"
replace margin = 37.35205 if district_name == "ORKNEY & SHETLAND"
replace margin = 26.90718 if district_name == "PAISLEY & RENFREWSHIRE NORTH"
replace margin = 34.94981 if district_name == "PAISLEY & RENFREWSHIRE SOUTH"
replace margin = 3.311561 if district_name == "PERTH & NORTH PERTHSHIRE"
replace margin = 43.79187 if district_name == "ROSS, SKYE & LOCHABER"
replace margin = 37.24371 if district_name == "RUTHERGLEN & HAMILTON WEST"
replace margin = 10.91071 if district_name == "STIRLING"
replace margin = 17.93844 if district_name == "ABERDEENSHIRE WEST & KINCARDINE"
replace margin = 30.18346 if district_name == "DUNBARTONSHIRE WEST"

* Effective number of electoral parties by district

gen enep = .

replace enep = 2.985307 if district_name == "BEDFORD"
replace enep = 3.27216 if district_name == "READING EAST"
replace enep = 2.591919 if district_name == "EPSOM & EWELL"
replace enep = 2.968326 if district_name == "ESHER & WALTON"
replace enep = 2.577962 if district_name == "GUILDFORD"
replace enep = 2.463367 if district_name == "MOLE VALLEY"
replace enep = 2.91929 if district_name == "REIGATE"
replace enep = 2.8176 if district_name == "RUNNYMEDE & WEYBRIDGE"
replace enep = 2.398075 if district_name == "SURREY SOUTH WEST"
replace enep = 2.769357 if district_name == "SPELTHORNE"
replace enep = 2.652587 if district_name == "SURREY HEATH"
replace enep = 2.763275 if district_name == "WOKING"
replace enep = 2.899178 if district_name == "READING WEST"
replace enep = 2.823766 if district_name == "ARUNDEL & SOUTH DOWNS"
replace enep = 3.142189 if district_name == "BOGNOR REGIS & LITTLEHAMPTON"
replace enep = 2.88829 if district_name == "CHICHESTER"
replace enep = 3.001621 if district_name == "CRAWLEY"
replace enep = 3.116477 if district_name == "EAST WORTHING & SHOREHAM"
replace enep = 2.819013 if district_name == "HORSHAM"
replace enep = 2.644826 if district_name == "MID SUSSEX"
replace enep = 2.951235 if district_name == "WORTHING WEST"
replace enep = 2.94863 if district_name == "CAMBRIDGE"
replace enep = 2.743518 if district_name == "HUNTINGDON"
replace enep = 3.053611 if district_name == "SLOUGH"
replace enep = 2.872304 if district_name == "NORTH EAST CAMBRIDGESHIRE"
replace enep = 3.011208 if district_name == "NORTH WEST CAMBRIDGESHIRE"
replace enep = 2.988374 if district_name == "PETERBOROUGH"
replace enep = 3.01371 if district_name == "SOUTH CAMBRIDGESHIRE"
replace enep = 2.725413 if district_name == "SOUTH EAST CAMBRIDGESHIRE"
replace enep = 2.715781 if district_name == "GREAT YARMOUTH"
replace enep = 3.041982 if district_name == "MID NORFOLK"
replace enep = 2.379385 if district_name == "NORTH NORFOLK"
replace enep = 2.652875 if district_name == "NORFOLK NORTH WEST"
replace enep = 2.930609 if district_name == "NORWICH NORTH"
replace enep = 2.838597 if district_name == "WINDSOR"
replace enep = 3.459563 if district_name == "NORWICH SOUTH"
replace enep = 2.932433 if district_name == "SOUTH NORFOLK"
replace enep = 2.939017 if district_name == "NORFOLK SOUTH WEST"
replace enep = 3.009232 if district_name == "BURY ST EDMUNDS"
replace enep = 3.101477 if district_name == "CENTRAL SUFFOLK & NORTH IPSWICH"
replace enep = 3.017214 if district_name == "IPSWICH"
replace enep = 3.124267 if district_name == "SOUTH SUFFOLK"
replace enep = 3.116083 if district_name == "SUFFOLK COASTAL"
replace enep = 2.909813 if district_name == "WAVENEY"
replace enep = 2.81022 if district_name == "WEST SUFFOLK"
replace enep = 2.765722 if district_name == "WOKINGHAM"
replace enep = 3.078386 if district_name == "BARKING"
replace enep = 2.885125 if district_name == "BATTERSEA"
replace enep = 2.979787 if district_name == "BECKENHAM"
replace enep = 3.193177 if district_name == "BETHNAL GREEN & BOW"
replace enep = 2.780573 if district_name == "BEXLEYHEATH & CRAYFORD"
replace enep = 2.577061 if district_name == "BRENT EAST"
replace enep = 2.680259 if district_name == "BRENT NORTH"
replace enep = 2.413224 if district_name == "BRENT SOUTH"
replace enep = 3.256417 if district_name == "BRENTFORD & ISLEWORTH"
replace enep = 2.81018 if district_name == "BROMLEY & CHISLEHURST"
replace enep = 2.828619 if district_name == "AYLESBURY"
replace enep = 2.104591 if district_name == "CAMBERWELL & PECKHAM"
replace enep = 2.965024 if district_name == "CARSHALTON & WALLINGTON"
replace enep = 2.623756 if district_name == "CHINGFORD & WOODFORD GREEN"
replace enep = 2.855166 if district_name == "CHIPPING BARNET"
replace enep = 3.006022 if district_name == "CITIES OF LONDON & WESTMINSTER"
replace enep = 2.843245 if district_name == "CROYDON CENTRAL"
replace enep = 2.689508 if district_name == "CROYDON NORTH"
replace enep = 2.704199 if district_name == "CROYDON SOUTH"
replace enep = 2.886768 if district_name == "DAGENHAM"
replace enep = 3.120017 if district_name == "DULWICH & WEST NORWOOD"
replace enep = 2.573213 if district_name == "BEACONSFIELD"
replace enep = 2.884367 if district_name == "EALING, SOUTHALL"
replace enep = 2.994685 if district_name == "EALING NORTH"
replace enep = 3.134442 if district_name == "EALING, ACTON & SHEPHERD'S BUSH"
replace enep = 2.714317 if district_name == "EAST HAM"
replace enep = 2.56991 if district_name == "EDMONTON"
replace enep = 2.968667 if district_name == "ELTHAM"
replace enep = 2.715226 if district_name == "ENFIELD NORTH"
replace enep = 2.654522 if district_name == "ENFIELD, SOUTHGATE"
replace enep = 2.646121 if district_name == "ERITH & THAMESMEAD"
replace enep = 2.907019 if district_name == "FELTHAM & HESTON"
replace enep = 2.443706 if district_name == "BUCKINGHAM"
replace enep = 2.908176 if district_name == "FINCHLEY & GOLDERS GREEN"
replace enep = 2.981785 if district_name == "GREENWICH & WOOLWICH"
replace enep = 3.033044 if district_name == "HACKNEY NORTH & STOKE NEWINGTON"
replace enep = 2.789554 if district_name == "HACKNEY SOUTH & SHOREDITCH"
replace enep = 2.827303 if district_name == "HAMMERSMITH & FULHAM"
replace enep = 3.284087 if district_name == "HAMPSTEAD & HIGHGATE"
replace enep = 2.688433 if district_name == "HARROW EAST"
replace enep = 2.802628 if district_name == "HARROW WEST"
replace enep = 2.372269 if district_name == "HAYES & HARLINGTON"
replace enep = 2.757471 if district_name == "HENDON"
replace enep = 2.612495 if district_name == "CHESHAM & AMERSHAM"
replace enep = 3.166227 if district_name == "HOLBORN & ST PANCRAS"
replace enep = 2.712232 if district_name == "HORNCHURCH"
replace enep = 2.827175 if district_name == "HORNSEY & WOOD GREEN"
replace enep = 2.710011 if district_name == "ILFORD NORTH"
replace enep = 2.808311 if district_name == "ILFORD SOUTH"
replace enep = 2.701428 if district_name == "ISLINGTON NORTH"
replace enep = 3.006311 if district_name == "ISLINGTON SOUTH & FINSBURY"
replace enep = 2.478055 if district_name == "KENSINGTON & CHELSEA"
replace enep = 2.578724 if district_name == "KINGSTON & SURBITON"
replace enep = 3.10039 if district_name == "LEWISHAM EAST"
replace enep = 3.047383 if district_name == "MILTON KEYNES SOUTH WEST"
replace enep = 2.780967 if district_name == "LEWISHAM WEST"
replace enep = 2.660215 if district_name == "LEWISHAM, DEPTFORD"
replace enep = 3.057668 if district_name == "LEYTON & WANSTEAD"
replace enep = 2.487431 if district_name == "MITCHAM & MORDEN"
replace enep = 2.849173 if district_name == "SOUTHWARK NORTH & BERMONDSEY"
replace enep = 2.84346 if district_name == "OLD BEXLEY & SIDCUP"
replace enep = 2.468234 if district_name == "ORPINGTON"
replace enep = 3.495194 if district_name == "POPLAR & CANNING TOWN"
replace enep = 2.869366 if district_name == "PUTNEY"
replace enep = 3.052852 if district_name == "REGENT'S PARK & KENSINGTON NORTH"
replace enep = 2.730944 if district_name == "LUTON NORTH"
replace enep = 3.083504 if district_name == "NORTH EAST MILTON KEYNES"
replace enep = 2.597981 if district_name == "RICHMOND PARK"
replace enep = 2.305818 if district_name == "ROMFORD"
replace enep = 2.945925 if district_name == "RUISLIP - NORTHWOOD"
replace enep = 2.988179 if district_name == "STREATHAM"
replace enep = 2.505572 if district_name == "SUTTON & CHEAM"
replace enep = 3.125576 if district_name == "TOOTING"
replace enep = 2.52613 if district_name == "TOTTENHAM"
replace enep = 2.586808 if district_name == "TWICKENHAM"
replace enep = 2.832804 if district_name == "UPMINSTER"
replace enep = 2.790885 if district_name == "UXBRIDGE"
replace enep = 2.941773 if district_name == "WYCOMBE"
replace enep = 2.681244 if district_name == "VAUXHALL"
replace enep = 2.767992 if district_name == "WALTHAMSTOW"
replace enep = 2.806762 if district_name == "WEST HAM"
replace enep = 2.995222 if district_name == "WIMBLEDON"
replace enep = 2.995901 if district_name == "BATH"
replace enep = 3.078047 if district_name == "BRISTOL EAST"
replace enep = 2.948351 if district_name == "BRISTOL NORTH WEST"
replace enep = 2.946132 if district_name == "BRISTOL SOUTH"
replace enep = 3.244182 if district_name == "BRISTOL WEST"
replace enep = 2.792594 if district_name == "KINGSWOOD"
replace enep = 2.708949 if district_name == "BEXHILL & BATTLE"
replace enep = 2.508452 if district_name == "NORTHAVON"
replace enep = 2.928139 if district_name == "WANSDYKE"
replace enep = 3.027316 if district_name == "WESTON-SUPER-MARE"
replace enep = 3.152019 if district_name == "WOODSPRING"
replace enep = 3.413736 if district_name == "FALMOUTH & CAMBORNE"
replace enep = 2.939526 if district_name == "CORNWALL NORTH"
replace enep = 2.806966 if district_name == "SOUTH EAST CORNWALL"
replace enep = 2.790143 if district_name == "ST IVES"
replace enep = 2.883777 if district_name == "TRURO & ST AUSTELL"
replace enep = 2.917882 if district_name == "EAST DEVON"
replace enep = 3.25854 if district_name == "BRIGHTON, KEMPTOWN"
replace enep = 3.362997 if district_name == "EXETER"
replace enep = 2.789118 if district_name == "NORTH DEVON"
replace enep = 3.240025 if district_name == "PLYMOUTH, DEVONPORT"
replace enep = 3.226001 if district_name == "PLYMOUTH, SUTTON"
replace enep = 3.123698 if district_name == "SOUTH WEST DEVON"
replace enep = 2.834364 if district_name == "TEIGNBRIDGE"
replace enep = 2.939087 if district_name == "TIVERTON & HONITON"
replace enep = 3.046335 if district_name == "TORBAY"
replace enep = 2.934764 if district_name == "TORRIDGE & WEST DEVON"
replace enep = 2.946182 if district_name == "TOTNES"
replace enep = 3.726495 if district_name == "BRIGHTON, PAVILION"
replace enep = 2.958372 if district_name == "BOURNEMOUTH EAST"
replace enep = 3.166834 if district_name == "BOURNEMOUTH WEST"
replace enep = 2.587617 if district_name == "CHRISTCHURCH"
replace enep = 2.59418 if district_name == "MID DORSET & NORTH POOLE"
replace enep = 2.647394 if district_name == "NORTH DORSET"
replace enep = 3.069304 if district_name == "POOLE"
replace enep = 2.905973 if district_name == "SOUTH DORSET"
replace enep = 2.503142 if district_name == "DORSET WEST"
replace enep = 3.041826 if district_name == "CHELTENHAM"
replace enep = 2.784052 if district_name == "COTSWOLD"
replace enep = 2.687789 if district_name == "EASTBOURNE"
replace enep = 3.00051 if district_name == "FOREST OF DEAN"
replace enep = 2.805729 if district_name == "GLOUCESTER"
replace enep = 2.992707 if district_name == "STROUD"
replace enep = 2.790249 if district_name == "TEWKESBURY"
replace enep = 3.111304 if district_name == "BRIDGWATER"
replace enep = 2.595348 if district_name == "SOMERTON & FROME"
replace enep = 2.622328 if district_name == "TAUNTON"
replace enep = 2.792214 if district_name == "WELLS"
replace enep = 2.537353 if district_name == "YEOVIL"
replace enep = 2.859384 if district_name == "DEVIZES"
replace enep = 2.917402 if district_name == "HASTINGS & RYE"
replace enep = 2.784024 if district_name == "SWINDON NORTH"
replace enep = 2.661065 if district_name == "NORTH WILTSHIRE"
replace enep = 2.95177 if district_name == "SALISBURY"
replace enep = 3.005398 if district_name == "SOUTH SWINDON"
replace enep = 2.849335 if district_name == "WESTBURY"
replace enep = 2.673773 if district_name == "BROMSGROVE"
replace enep = 2.701268 if district_name == "HEREFORD"
replace enep = 2.755626 if district_name == "LEOMINSTER"
replace enep = 2.738563 if district_name == "MID WORCESTERSHIRE"
replace enep = 2.74361 if district_name == "REDDITCH"
replace enep = 3.200899 if district_name == "HOVE"
replace enep = 2.727276 if district_name == "WEST WORCESTERSHIRE"
replace enep = 3.034874 if district_name == "WORCESTER"
replace enep = 2.706256 if district_name == "WYRE FOREST"
replace enep = 2.619987 if district_name == "LUDLOW"
replace enep = 2.824134 if district_name == "NORTH SHROPSHIRE"
replace enep = 3.190434 if district_name == "SHREWSBURY & ATCHAM"
replace enep = 2.767229 if district_name == "TELFORD"
replace enep = 2.796649 if district_name == "WREKIN, THE"
replace enep = 2.959803 if district_name == "BURTON"
replace enep = 2.672815 if district_name == "CANNOCK CHASE"
replace enep = 2.494133 if district_name == "LEWES"
replace enep = 2.723843 if district_name == "LICHFIELD"
replace enep = 3.168392 if district_name == "NEWCASTLE-UNDER-LYME"
replace enep = 2.870984 if district_name == "SOUTH STAFFORDSHIRE"
replace enep = 2.750834 if district_name == "STAFFORD"
replace enep = 3.084065 if district_name == "STAFFORDSHIRE MOORLANDS"
replace enep = 2.810323 if district_name == "STOKE-ON-TRENT CENTRAL"
replace enep = 2.818682 if district_name == "STOKE-ON-TRENT NORTH"
replace enep = 3.127347 if district_name == "STOKE-ON-TRENT SOUTH"
replace enep = 2.806333 if district_name == "STONE"
replace enep = 2.892209 if district_name == "TAMWORTH"
replace enep = 2.775944 if district_name == "WEALDEN"
replace enep = 2.814599 if district_name == "NORTH WARWICKSHIRE"
replace enep = 2.742237 if district_name == "NUNEATON"
replace enep = 2.860633 if district_name == "RUGBY & KENILWORTH"
replace enep = 2.817416 if district_name == "STRATFORD ON AVON"
replace enep = 2.860431 if district_name == "WARWICK & LEAMINGTON"
replace enep = 2.806318 if district_name == "ALDRIDGE - BROWNHILLS"
replace enep = 2.828111 if district_name == "BIRMINGHAM, EDGBASTON"
replace enep = 2.743513 if district_name == "BIRMINGHAM, ERDINGTON"
replace enep = 2.816115 if district_name == "BIRMINGHAM, HALL GREEN"
replace enep = 2.86993 if district_name == "BIRMINGHAM, HODGE HILL"
replace enep = 3.157597 if district_name == "LUTON SOUTH"
replace enep = 2.94384 if district_name == "BASILDON"
replace enep = 2.608083 if district_name == "BIRMINGHAM, LADYWOOD"
replace enep = 2.822009 if district_name == "BIRMINGHAM, NORTHFIELD"
replace enep = 3.045188 if district_name == "BIRMINGHAM, PERRY BARR"
replace enep = 3.025965 if district_name == "BIRMINGHAM, SELLY OAK"
replace enep = 3.344823 if district_name == "BIRMINGHAM, SPARKBROOK & SMALL HEATH"
replace enep = 2.715855 if district_name == "BIRMINGHAM, YARDLEY"
replace enep = 2.547745 if district_name == "COVENTRY NORTH EAST"
replace enep = 2.924017 if district_name == "COVENTRY NORTH WEST"
replace enep = 2.95865 if district_name == "COVENTRY SOUTH"
replace enep = 3.091502 if district_name == "DUDLEY NORTH"
replace enep = 2.645673 if district_name == "BILLERICAY"
replace enep = 2.891986 if district_name == "DUDLEY SOUTH"
replace enep = 2.739423 if district_name == "HALESOWEN & ROWLEY REGIS"
replace enep = 2.727356 if district_name == "MERIDEN"
replace enep = 2.929551 if district_name == "SOLIHULL"
replace enep = 2.812874 if district_name == "STOURBRIDGE"
replace enep = 2.681364 if district_name == "SUTTON COLDFIELD"
replace enep = 2.973232 if district_name == "WALSALL NORTH"
replace enep = 2.848229 if district_name == "WALSALL SOUTH"
replace enep = 2.66783 if district_name == "WARLEY"
replace enep = 2.598927 if district_name == "WEST BROMWICH EAST"
replace enep = 2.809306 if district_name == "BRAINTREE"
replace enep = 2.675979 if district_name == "WEST BROMWICH WEST"
replace enep = 2.498629 if district_name == "WOLVERHAMPTON NORTH EAST"
replace enep = 2.366266 if district_name == "WOLVERHAMPTON SOUTH EAST"
replace enep = 2.799282 if district_name == "WOLVERHAMPTON SOUTH WEST"
replace enep = 2.872443 if district_name == "AMBER VALLEY"
replace enep = 2.060607 if district_name == "BOLSOVER"
replace enep = 2.528296 if district_name == "CHESTERFIELD"
replace enep = 2.876798 if district_name == "DERBY NORTH"
replace enep = 2.877883 if district_name == "DERBY SOUTH"
replace enep = 3.10375 if district_name == "EREWASH"
replace enep = 2.603799 if district_name == "BRENTWOOD & ONGAR"
replace enep = 2.914383 if district_name == "HIGH PEAK"
replace enep = 2.821659 if district_name == "NORTH EAST DERBYSHIRE"
replace enep = 2.841426 if district_name == "SOUTH DERBYSHIRE"
replace enep = 2.864629 if district_name == "WEST DERBYSHIRE"
replace enep = 2.990302 if district_name == "BLABY"
replace enep = 3.029831 if district_name == "BOSWORTH"
replace enep = 2.958594 if district_name == "CHARNWOOD"
replace enep = 2.921386 if district_name == "HARBOROUGH"
replace enep = 2.447533 if district_name == "LEICESTER EAST"
replace enep = 3.388679 if district_name == "LEICESTER SOUTH"
replace enep = 2.871213 if district_name == "CASTLE POINT"
replace enep = 2.764362 if district_name == "LEICESTER WEST"
replace enep = 2.923366 if district_name == "LOUGHBOROUGH"
replace enep = 2.81425 if district_name == "NORTH WEST LEICESTERSHIRE"
replace enep = 2.763777 if district_name == "RUTLAND & MELTON"
replace enep = 2.936442 if district_name == "BOSTON & SKEGNESS"
replace enep = 3.033636 if district_name == "GAINSBOROUGH"
replace enep = 2.880422 if district_name == "GRANTHAM & STAMFORD"
replace enep = 2.871074 if district_name == "LINCOLN"
replace enep = 3.043351 if district_name == "LOUTH & HORNCASTLE"
replace enep = 2.787433 if district_name == "SLEAFORD & NORTH HYKEHAM"
replace enep = 2.698221 if district_name == "COLCHESTER"
replace enep = 2.46783 if district_name == "SOUTH HOLLAND & THE DEEPINGS"
replace enep = 2.669407 if district_name == "CORBY"
replace enep = 2.698709 if district_name == "DAVENTRY"
replace enep = 2.618413 if district_name == "KETTERING"
replace enep = 3.138537 if district_name == "NORTHAMPTON NORTH"
replace enep = 2.90547 if district_name == "NORTHAMPTON SOUTH"
replace enep = 2.701079 if district_name == "WELLINGBOROUGH"
replace enep = 3.012686 if district_name == "ASHFIELD"
replace enep = 2.337286 if district_name == "BASSETLAW"
replace enep = 2.921811 if district_name == "BROXTOWE"
replace enep = 2.740295 if district_name == "EPPING FOREST"
replace enep = 2.681372 if district_name == "GEDLING"
replace enep = 3.097776 if district_name == "MANSFIELD"
replace enep = 2.693508 if district_name == "NEWARK"
replace enep = 3.117063 if district_name == "NOTTINGHAM EAST"
replace enep = 2.427647 if district_name == "NOTTINGHAM NORTH"
replace enep = 2.896844 if district_name == "NOTTINGHAM SOUTH"
replace enep = 2.85437 if district_name == "RUSHCLIFFE"
replace enep = 2.686881 if district_name == "SHERWOOD"
replace enep = 3.023653 if district_name == "BEVERLEY & HOLDERNESS"
replace enep = 2.695486 if district_name == "BRIGG & GOOLE"
replace enep = 2.784647 if district_name == "HARLOW"
replace enep = 2.851747 if district_name == "CLEETHORPES"
replace enep = 2.903818 if district_name == "EAST YORKSHIRE"
replace enep = 3.076048 if district_name == "GREAT GRIMSBY"
replace enep = 2.647527 if district_name == "HALTEMPRICE & HOWDEN"
replace enep = 2.590447 if district_name == "KINGSTON UPON HULL EAST"
replace enep = 2.730292 if district_name == "KINGSTON UPON HULL NORTH"
replace enep = 2.557343 if district_name == "KINGSTON UPON HULL WEST & HESSLE"
replace enep = 2.638692 if district_name == "SCUNTHORPE"
replace enep = 2.343166 if district_name == "HARROGATE & KNARESBOROUGH"
replace enep = 2.376307 if district_name == "RICHMOND (YORKS)"
replace enep = 2.800701 if district_name == "HARWICH"
replace enep = 2.94855 if district_name == "RYEDALE"
replace enep = 2.913107 if district_name == "SCARBOROUGH & WHITBY"
replace enep = 2.59759 if district_name == "SELBY"
replace enep = 2.815816 if district_name == "SKIPTON & RIPON"
replace enep = 2.606033 if district_name == "VALE OF YORK"
replace enep = 3.016764 if district_name == "YORK, CITY OF"
replace enep = 2.344907 if district_name == "BARNSLEY CENTRAL"
replace enep = 2.180815 if district_name == "BARNSLEY EAST & MEXBOROUGH"
replace enep = 2.459595 if district_name == "BARNSLEY WEST & PENISTONE"
replace enep = 2.525773 if district_name == "DON VALLEY"
replace enep = 2.732712 if district_name == "MALDON & EAST CHELMSFORD"
replace enep = 2.813221 if district_name == "DONCASTER CENTRAL"
replace enep = 2.663382 if district_name == "DONCASTER NORTH"
replace enep = 2.64435 if district_name == "ROTHER VALLEY"
replace enep = 2.823498 if district_name == "ROTHERHAM"
replace enep = 2.392037 if district_name == "SHEFFIELD, ATTERCLIFFE"
replace enep = 1.985745 if district_name == "SHEFFIELD, BRIGHTSIDE"
replace enep = 2.883798 if district_name == "SHEFFIELD CENTRAL"
replace enep = 2.695421 if district_name == "SHEFFIELD, HALLAM"
replace enep = 2.724994 if district_name == "SHEFFIELD, HEELEY"
replace enep = 2.773505 if district_name == "SHEFFIELD, HILLSBOROUGH"
replace enep = 3.057201 if district_name == "MID BEDFORDSHIRE"
replace enep = 2.985501 if district_name == "NORTH ESSEX"
replace enep = 2.421915 if district_name == "WENTWORTH"
replace enep = 2.98261 if district_name == "BATLEY & SPEN"
replace enep = 3.131279 if district_name == "BRADFORD NORTH"
replace enep = 2.987373 if district_name == "BRADFORD SOUTH"
replace enep = 3.285516 if district_name == "BRADFORD WEST"
replace enep = 3.157879 if district_name == "CALDER VALLEY"
replace enep = 3.338532 if district_name == "COLNE VALLEY"
replace enep = 3.366906 if district_name == "DEWSBURY"
replace enep = 2.625717 if district_name == "ELMET"
replace enep = 3.105594 if district_name == "HALIFAX"
replace enep = 2.557351 if district_name == "RAYLEIGH"
replace enep = 2.378729 if district_name == "HEMSWORTH"
replace enep = 3.070007 if district_name == "HUDDERSFIELD"
replace enep = 2.941454 if district_name == "KEIGHLEY"
replace enep = 2.374798 if district_name == "LEEDS CENTRAL"
replace enep = 2.339739 if district_name == "LEEDS EAST"
replace enep = 2.875438 if district_name == "LEEDS NORTH EAST"
replace enep = 3.178196 if district_name == "LEEDS NORTH WEST"
replace enep = 2.667089 if district_name == "LEEDS WEST"
replace enep = 3.088845 if district_name == "MORLEY & ROTHWELL"
replace enep = 2.806789 if district_name == "NORMANTON"
replace enep = 3.001364 if district_name == "ROCHFORD & SOUTHEND EAST"
replace enep = 2.199526 if district_name == "PONTEFRACT & CASTLEFORD"
replace enep = 2.824937 if district_name == "PUDSEY"
replace enep = 3.065802 if district_name == "SHIPLEY"
replace enep = 3.112498 if district_name == "WAKEFIELD"
replace enep = 2.98257 if district_name == "CHESTER, CITY OF"
replace enep = 2.815525 if district_name == "CONGLETON"
replace enep = 2.637174 if district_name == "CREWE & NANTWICH"
replace enep = 2.811794 if district_name == "EDDISBURY"
replace enep = 2.710769 if district_name == "ELLESMERE PORT & NESTON"
replace enep = 2.156045 if district_name == "HALTON"
replace enep = 2.727463 if district_name == "SAFFRON WALDEN"
replace enep = 2.712715 if district_name == "MACCLESFIELD"
replace enep = 2.691701 if district_name == "TATTON"
replace enep = 2.639727 if district_name == "WARRINGTON NORTH"
replace enep = 3.025265 if district_name == "WARRINGTON SOUTH"
replace enep = 2.803324 if district_name == "WEAVER VALE"
replace enep = 2.822899 if district_name == "ALTRINCHAM & SALE WEST"
replace enep = 2.529838 if district_name == "ASHTON-UNDER-LYNE"
replace enep = 2.804183 if district_name == "BOLTON NORTH EAST"
replace enep = 2.48171 if district_name == "BOLTON SOUTH EAST"
replace enep = 2.830686 if district_name == "BOLTON WEST"
replace enep = 3.057557 if district_name == "SOUTHEND WEST"
replace enep = 2.914131 if district_name == "BURY NORTH"
replace enep = 2.746693 if district_name == "BURY SOUTH"
replace enep = 2.436968 if district_name == "CHEADLE"
replace enep = 2.510694 if district_name == "DENTON & REDDISH"
replace enep = 2.504972 if district_name == "ECCLES"
replace enep = 2.743233 if district_name == "HAZEL GROVE"
replace enep = 2.953654 if district_name == "HEYWOOD & MIDDLETON"
replace enep = 2.223388 if district_name == "LEIGH"
replace enep = 2.245612 if district_name == "MAKERFIELD"
replace enep = 2.251928 if district_name == "MANCHESTER, BLACKLEY"
replace enep = 2.857026 if district_name == "THURROCK"
replace enep = 2.421759 if district_name == "MANCHESTER CENTRAL"
replace enep = 2.475985 if district_name == "MANCHESTER, GORTON"
replace enep = 2.780994 if district_name == "MANCHESTER, WITHINGTON"
replace enep = 3.125451 if district_name == "OLDHAM EAST & SADDLEWORTH"
replace enep = 2.977286 if district_name == "OLDHAM WEST & ROYTON"
replace enep = 2.880163 if district_name == "ROCHDALE"
replace enep = 2.457588 if district_name == "SALFORD"
replace enep = 2.8878 if district_name == "STALYBRIDGE & HYDE"
replace enep = 2.733673 if district_name == "STOCKPORT"
replace enep = 2.676666 if district_name == "STRETFORD & URMSTON"
replace enep = 2.956079 if district_name == "WEST CHELMSFORD"
replace enep = 2.613618 if district_name == "WIGAN"
replace enep = 2.750654 if district_name == "WORSLEY"
replace enep = 2.706664 if district_name == "WYTHENSHAWE & SALE EAST"
replace enep = 3.421601 if district_name == "BLACKBURN"
replace enep = 2.675866 if district_name == "BLACKPOOL NORTH & FLEETWOOD"
replace enep = 2.716207 if district_name == "BLACKPOOL SOUTH"
replace enep = 3.460589 if district_name == "BURNLEY"
replace enep = 2.491771 if district_name == "CHORLEY"
replace enep = 2.613438 if district_name == "FYLDE"
replace enep = 2.949338 if district_name == "HYNDBURN"
replace enep = 3.052432 if district_name == "ALDERSHOT"
replace enep = 2.994198 if district_name == "LANCASTER & WYRE"
replace enep = 2.517696 if district_name == "MORECAMBE & LUNESDALE"
replace enep = 3.350481 if district_name == "PENDLE"
replace enep = 2.897202 if district_name == "PRESTON"
replace enep = 2.678728 if district_name == "RIBBLE VALLEY"
replace enep = 3.009187 if district_name == "ROSSENDALE & DARWEN"
replace enep = 2.787208 if district_name == "SOUTH RIBBLE"
replace enep = 2.719037 if district_name == "WEST LANCASHIRE"
replace enep = 2.066704 if district_name == "BIRKENHEAD"
replace enep = 1.689476 if district_name == "BOOTLE"
replace enep = 3.132795 if district_name == "BASINGSTOKE"
replace enep = 2.727068 if district_name == "CROSBY"
replace enep = 2.180726 if district_name == "KNOWSLEY NORTH & SEFTON EAST"
replace enep = 1.933069 if district_name == "KNOWSLEY SOUTH"
replace enep = 2.413171 if district_name == "LIVERPOOL, GARSTON"
replace enep = 2.448985 if district_name == "LIVERPOOL, RIVERSIDE"
replace enep = 1.783876 if district_name == "LIVERPOOL, WALTON"
replace enep = 2.366 if district_name == "LIVERPOOL, WAVERTREE"
replace enep = 2.254196 if district_name == "LIVERPOOL, WEST DERBY"
replace enep = 2.704835 if district_name == "SOUTHPORT"
replace enep = 2.468106 if district_name == "ST HELENS NORTH"
replace enep = 2.77834 if district_name == "EAST HAMPSHIRE"
replace enep = 2.525006 if district_name == "ST HELENS SOUTH"
replace enep = 2.456913 if district_name == "WALLASEY"
replace enep = 2.955925 if district_name == "WIRRAL SOUTH"
replace enep = 2.729746 if district_name == "WIRRAL WEST"
replace enep = 2.833612 if district_name == "BARROW & FURNESS"
replace enep = 2.758317 if district_name == "CARLISLE"
replace enep = 2.684499 if district_name == "COPELAND"
replace enep = 2.717181 if district_name == "PENRITH & THE BORDER"
replace enep = 2.410491 if district_name == "WESTMORLAND & LONSDALE"
replace enep = 2.725546 if district_name == "WORKINGTON"
replace enep = 2.793277 if district_name == "BEDFORDSHIRE NORTH EAST"
replace enep = 3.004048 if district_name == "EASTLEIGH"
replace enep = 2.665116 if district_name == "HARTLEPOOL"
replace enep = 2.497717 if district_name == "MIDDLESBROUGH"
replace enep = 2.667707 if district_name == "MIDDLESBROUGH SOUTH & EAST CLEVELAND"
replace enep = 2.874138 if district_name == "REDCAR"
replace enep = 2.607416 if district_name == "STOCKTON NORTH"
replace enep = 2.694264 if district_name == "STOCKTON SOUTH"
replace enep = 2.780531 if district_name == "BISHOP AUCKLAND"
replace enep = 2.650454 if district_name == "DARLINGTON"
replace enep = 2.557125 if district_name == "DURHAM, CITY OF"
replace enep = 1.852477 if district_name == "EASINGTON"
replace enep = 2.770808 if district_name == "FAREHAM"
replace enep = 2.102966 if district_name == "NORTH DURHAM"
replace enep = 2.724994 if district_name == "NORTH WEST DURHAM"
replace enep = 2.477523 if district_name == "SEDGEFIELD"
replace enep = 2.527371 if district_name == "BERWICK-UPON-TWEED"
replace enep = 2.391002 if district_name == "BLYTH VALLEY"
replace enep = 2.957725 if district_name == "HEXHAM"
replace enep = 2.513924 if district_name == "WANSBECK"
replace enep = 2.40467 if district_name == "BLAYDON"
replace enep = 2.296943 if district_name == "GATESHEAD EAST & WASHINGTON WEST"
replace enep = 2.144146 if district_name == "HOUGHTON & WASHINGTON EAST"
replace enep = 3.010824 if district_name == "GOSPORT"
replace enep = 2.338636 if district_name == "JARROW"
replace enep = 2.877495 if district_name == "NEWCASTLE UPON TYNE CENTRAL"
replace enep = 2.659674 if district_name == "NEWCASTLE UPON TYNE NORTH"
replace enep = 2.412444 if district_name == "NEWCASTLE UPON TYNE EAST & WALLSEND"
replace enep = 2.187668 if district_name == "NORTH TYNESIDE"
replace enep = 2.298517 if district_name == "SOUTH SHIELDS"
replace enep = 2.711176 if district_name == "SUNDERLAND NORTH"
replace enep = 2.398924 if district_name == "SUNDERLAND SOUTH"
replace enep = 2.282101 if district_name == "TYNE BRIDGE"
replace enep = 2.598722 if district_name == "TYNEMOUTH"
replace enep = 3.077344 if district_name == "HAVANT"
replace enep = 2.976307 if district_name == "ALYN & DEESIDE"
replace enep = 3.299396 if district_name == "CLWYD SOUTH"
replace enep = 3.43768 if district_name == "CLWYD WEST"
replace enep = 3.167965 if district_name == "DELYN"
replace enep = 3.012766 if district_name == "VALE OF CLWYD"
replace enep = 3.192287 if district_name == "WREXHAM"
replace enep = 3.132466 if district_name == "CARMARTHEN EAST & DINEFWR"
replace enep = 3.576747 if district_name == "CARMARTHEN WEST & SOUTH PEMBROKESHIRE"
replace enep = 3.409568 if district_name == "CEREDIGION"
replace enep = 3.069031 if district_name == "LLANELLI"
replace enep = 2.704986 if district_name == "NEW FOREST EAST"
replace enep = 3.462525 if district_name == "PRESELI PEMBROKESHIRE"
replace enep = 2.212583 if district_name == "BLAENAU GWENT"
replace enep = 2.218386 if district_name == "ISLWYN"
replace enep = 2.679333 if district_name == "MONMOUTH"
replace enep = 3.139193 if district_name == "NEWPORT EAST"
replace enep = 3.091588 if district_name == "NEWPORT WEST"
replace enep = 2.629601 if district_name == "TORFAEN"
replace enep = 3.209366 if district_name == "CAERNARFON"
replace enep = 3.715047 if district_name == "CONWY"
replace enep = 2.942943 if district_name == "MEIRIONNYDD NANT CONWY"
replace enep = 2.575667 if district_name == "NEW FOREST WEST"
replace enep = 3.839498 if district_name == "YNYS-MON"
replace enep = 3.273934 if district_name == "BRIDGEND"
replace enep = 2.621722 if district_name == "CAERPHILLY"
replace enep = 2.220537 if district_name == "CYNON VALLEY"
replace enep = 2.453248 if district_name == "MERTHYR TYDFIL & RHYMNEY"
replace enep = 2.389215 if district_name == "OGMORE"
replace enep = 2.873188 if district_name == "PONTYPRIDD"
replace enep = 1.98989 if district_name == "RHONDDA"
replace enep = 2.898821 if district_name == "BRECON & RADNORSHIRE"
replace enep = 2.80616 if district_name == "MONTGOMERYSHIRE"
replace enep = 2.567238 if district_name == "NORTH EAST HAMPSHIRE"
replace enep = 2.656552 if district_name == "CARDIFF CENTRAL"
replace enep = 3.098844 if district_name == "CARDIFF NORTH"
replace enep = 3.128718 if district_name == "CARDIFF SOUTH & PENARTH"
replace enep = 3.311183 if district_name == "CARDIFF WEST"
replace enep = 3.034647 if district_name == "VALE OF GLAMORGAN"
replace enep = 2.465949 if district_name == "ABERAVON"
replace enep = 3.46386 if district_name == "GOWER"
replace enep = 2.928225 if district_name == "NEATH"
replace enep = 2.632163 if district_name == "SWANSEA EAST"
replace enep = 3.416015 if district_name == "SWANSEA WEST"
replace enep = 2.753288 if district_name == "NORTH WEST HAMPSHIRE"
replace enep = 2.916653 if district_name == "PORTSMOUTH NORTH"
replace enep = 2.938769 if district_name == "PORTSMOUTH SOUTH"
replace enep = 2.81842 if district_name == "SOUTH WEST BEDFORDSHIRE"
replace enep = 2.470582 if district_name == "ROMSEY"
replace enep = 2.848099 if district_name == "SOUTHAMPTON, ITCHEN"
replace enep = 3.170254 if district_name == "SOUTHAMPTON, TEST"
replace enep = 2.42843 if district_name == "WINCHESTER"
replace enep = 2.651587 if district_name == "BROXBOURNE"
replace enep = 2.842949 if district_name == "BELFAST EAST"
replace enep = 3.104781 if district_name == "BELFAST NORTH"
replace enep = 3.9947 if district_name == "BELFAST SOUTH"
replace enep = 1.886321 if district_name == "BELFAST WEST"
replace enep = 2.892428 if district_name == "EAST ANTRIM"
replace enep = 3.515808 if district_name == "EAST LONDONDERRY"
replace enep = 3.522464 if district_name == "FERMANAGH & SOUTH TYRONE"
replace enep = 2.877529 if district_name == "FOYLE"
replace enep = 2.878206 if district_name == "HEMEL HEMPSTEAD"
replace enep = 2.737308 if district_name == "LAGAN VALLEY"
replace enep = 3.086776 if district_name == "MID ULSTER"
replace enep = 3.477598 if district_name == "NEWRY & ARMAGH"
replace enep = 2.769363 if district_name == "NORTH ANTRIM"
replace enep = 2.595561 if district_name == "NORTH DOWN"
replace enep = 3.741506 if district_name == "SOUTH ANTRIM"
replace enep = 3.224688 if district_name == "SOUTH DOWN"
replace enep = 2.637112 if district_name == "STRANGFORD"
replace enep = 3.729967 if district_name == "UPPER BANN"
replace enep = 3.692895 if district_name == "WEST TYRONE"
replace enep = 2.845378 if district_name == "HERTFORD & STORTFORD"
replace enep = 2.556288 if district_name == "HERTSMERE"
replace enep = 2.741158 if district_name == "HITCHIN & HARPENDEN"
replace enep = 2.865613 if district_name == "HERTFORDSHIRE NORTH EAST"
replace enep = 2.805581 if district_name == "BRACKNELL"
replace enep = 2.824085 if district_name == "SOUTH WEST HERTFORDSHIRE"
replace enep = 3.103246 if district_name == "ST ALBANS"
replace enep = 2.906155 if district_name == "STEVENAGE"
replace enep = 3.321746 if district_name == "WATFORD"
replace enep = 2.51576 if district_name == "WELWYN HATFIELD"
replace enep = 2.791898 if district_name == "ISLE OF WIGHT"
replace enep = 2.756861 if district_name == "ASHFORD"
replace enep = 3.057125 if district_name == "CANTERBURY"
replace enep = 2.799897 if district_name == "CHATHAM & AYLESFORD"
replace enep = 2.744238 if district_name == "DARTFORD"
replace enep = 2.461312 if district_name == "MAIDENHEAD"
replace enep = 2.825358 if district_name == "DOVER"
replace enep = 2.743671 if district_name == "FAVERSHAM & MID KENT"
replace enep = 2.518767 if district_name == "FOLKESTONE & HYTHE"
replace enep = 2.788781 if district_name == "GILLINGHAM"
replace enep = 2.617991 if district_name == "GRAVESHAM"
replace enep = 2.656383 if district_name == "MAIDSTONE & THE WEALD"
replace enep = 2.713605 if district_name == "MEDWAY"
replace enep = 2.690048 if district_name == "NORTH THANET"
replace enep = 2.752366 if district_name == "SEVENOAKS"
replace enep = 2.7374 if district_name == "SITTINGBOURNE & SHEPPEY"
replace enep = 2.349197 if district_name == "NEWBURY"
replace enep = 2.969052 if district_name == "SOUTH THANET"
replace enep = 2.658978 if district_name == "TONBRIDGE & MALLING"
replace enep = 2.792093 if district_name == "TUNBRIDGE WELLS"
replace enep = 2.986861 if district_name == "BANBURY"
replace enep = 2.639753 if district_name == "HENLEY"
replace enep = 3.363088 if district_name == "OXFORD EAST"
replace enep = 2.900113 if district_name == "OXFORD WEST & ABINGDON"
replace enep = 3.105842 if district_name == "WANTAGE"
replace enep = 2.874038 if district_name == "WITNEY"
replace enep = 2.520344 if district_name == "EAST SURREY"
replace enep = 3.372573 if district_name == "ABERDEEN NORTH"
replace enep = 3.490083 if district_name == "ABERDEEN SOUTH"
replace enep = 2.503608 if district_name == "AIRDRIE & SHOTTS"
replace enep = 3.801366 if district_name == "ANGUS"
replace enep = 3.791264 if district_name == "ARGYLL & BUTE"
replace enep = 3.351774 if district_name == "AYR, CARRICK & CUMNOCK"
replace enep = 3.000928 if district_name == "BANFF & BUCHAN"
replace enep = 3.410447 if district_name == "BERWICKSHIRE, ROXBURGH & SELKIRK"
replace enep = 3.038083 if district_name == "CAITHNESS, SUTHERLAND & EASTER ROSS"
replace enep = 3.277168 if district_name == "AYRSHIRE CENTRAL"
replace enep = 2.199668 if district_name == "COATBRIDGE, CHRYSTON & BELLSHILL"
replace enep = 2.885889 if district_name == "CUMBERNAULD, KILSYTH & KIRKINTILLOCH EAST"
replace enep = 3.156234 if district_name == "DUMFRIES & GALLOWAY"
replace enep = 3.508766 if district_name == "DUMFRIESSHIRE, CLYDESDALE & TWEEDDALE"
replace enep = 3.338659 if district_name == "DUNDEE EAST"
replace enep = 3.15176 if district_name == "DUNDEE WEST"
replace enep = 3.192968 if district_name == "DUNFERMLINE & WEST FIFE"
replace enep = 3.166769 if district_name == "DUNBARTONSHIRE EAST"
replace enep = 3.209091 if district_name == "EAST KILBRIDE, STRATHAVEN & LESMAHAGOW"
replace enep = 3.591679 if district_name == "EAST LOTHIAN"
replace enep = 3.123326 if district_name == "EAST RENFREWSHIRE"
replace enep = 3.7553 if district_name == "EDINBURGH EAST"
replace enep = 3.943125 if district_name == "EDINBURGH NORTH & LEITH"
replace enep = 3.593331 if district_name == "EDINBURGH SOUTH"
replace enep = 3.691111 if district_name == "EDINBURGH SOUTH WEST"
replace enep = 3.05555 if district_name == "EDINBURGH WEST"
replace enep = 2.979175 if district_name == "NA H-EILEANAN AN IAR"
replace enep = 2.93998 if district_name == "FALKIRK"
replace enep = 3.260977 if district_name == "GLASGOW CENTRAL"
replace enep = 2.396385 if district_name == "GLASGOW EAST"
replace enep = 3.729776 if district_name == "GLASGOW NORTH"
replace enep = 1.410123 if district_name == "GLASGOW NORTH EAST"
replace enep = 3.181212 if district_name == "GLASGOW NORTH WEST"
replace enep = 3.350829 if district_name == "GLASGOW SOUTH"
replace enep = 2.451332 if district_name == "GLASGOW SOUTH WEST"
replace enep = 2.877367 if district_name == "GLENROTHES"
replace enep = 3.329331 if district_name == "GORDON"
replace enep = 2.979652 if district_name == "INVERCLYDE"
replace enep = 3.456013 if district_name == "INVERNESS, NAIRN, BADENOCH & STRATHSPEY"
replace enep = 3.069808 if district_name == "KILMARNOCK & LOUDOUN"
replace enep = 2.579168 if district_name == "KIRKCALDY & COWDENBEATH"
replace enep = 3.367136 if district_name == "LANARCK & HAMILTON EAST"
replace enep = 3.120328 if district_name == "LINLITHGOW & EAST FALKIRK"
replace enep = 2.924064 if district_name == "LIVINGSTONE"
replace enep = 3.187458 if district_name == "MIDLOTHIAN"
replace enep = 3.829584 if district_name == "MORAY"
replace enep = 2.61297 if district_name == "MOTHERWELL & WISHAW"
replace enep = 3.483869 if district_name == "NORTH AYRSHIRE & ARRAN"
replace enep = 2.947149 if district_name == "NORTH EAST FIFE"
replace enep = 3.951793 if district_name == "OCHIL & SOUTH PERTHSHIRE"
replace enep = 3.075664 if district_name == "ORKNEY & SHETLAND"
replace enep = 3.359052 if district_name == "PAISLEY & RENFREWSHIRE NORTH"
replace enep = 2.882945 if district_name == "PAISLEY & RENFREWSHIRE SOUTH"
replace enep = 3.747823 if district_name == "PERTH & NORTH PERTHSHIRE"
replace enep = 2.559739 if district_name == "ROSS, SKYE & LOCHABER"
replace enep = 2.697927 if district_name == "RUTHERGLEN & HAMILTON WEST"
replace enep = 3.929672 if district_name == "STIRLING"
replace enep = 3.077438 if district_name == "ABERDEENSHIRE WEST & KINCARDINE"
replace enep = 2.89869 if district_name == "DUNBARTONSHIRE WEST"


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

destring asintdat, gen(intdate)

gen surveydate = date(string(intdate,"%8.0f"),"DMY")

format %tdMon_DD,_CCYY surveydate

gen edate = 20050505

gen electiondate = date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

rename time declaration

gen time = electiondate - surveydate + 1

replace time = . if time < 0 | time > 900

* Gender

gen male = tq76

recode male 2=0

* Age

gen age = tq77

* Education

gen education = tq81

recode education 6=. 7=5 8=. 9=. 9999=.

* Interest for election

gen interest = aq1

recode interest (9=.)
recode interest (99=.)

replace interest = 5 - interest

* Party identification (district)

gen pid1 = aq9ax
recode pid1 999=.

gen partycloser1 = aq9cx
recode partycloser1 999=.

gen closer1 = aq9bx
recode closer1 99=.

gen pid2 = aq9ay
recode pid2 999=.

gen partycloser2 = aq9cy
recode partycloser2 999=.

gen closer2 = aq9by
recode closer2 99=.

egen partyid = rowmax(pid1 pid2)
egen partycloser = rowmax(partycloser1 partycloser2)
egen closer = rowmax(closer1 closer2)

gen pidstatus_district = .

replace pidstatus_district = 9999 if partyid == 98 & partycloser == 98 | partyid == 99 & partycloser == 99 | partyid == 98 & partycloser == 99 | partyid == 98 & partycloser == 99 | partyid == 98 & partycloser == .

replace pidstatus_district = 2 if partyid == 0 & closer == . & pidstatus_district!=9999 | partyid == 0 & closer == 2 & pidstatus_district!=9999 | partyid == 0 & closer == 8 & pidstatus_district!=9999 | partyid == 0 & closer == 9 & pidstatus_district!=9999 | partycloser == 0

replace pidstatus_district = 3 if partyid == constituency_2005 & pidstatus_district!=2 & pidstatus_district!=9999
replace pidstatus_district = 3 if partycloser == constituency_2005 & pidstatus_district!=2 & pidstatus_district!=9999

replace pidstatus_district = 1 if partyid!=constituency_2005 & partyid!=. & pidstatus_district!=2 & pidstatus_district!=3 & pidstatus_district!=9999
replace pidstatus_district = 1 if partycloser!=constituency_2005 & partycloser!=. & pidstatus_district!=2 & pidstatus_district!=3 & pidstatus_district!=9999

replace pidstatus_district = . if pidstatus_district == 9999

label define pidstatus 1 "Loser PID" 2 "No PID" 3 "Winner PID"
label values pidstatus_district pidstatus

* Party identification scale (district)

gen pidscale_district = .

replace pidscale_district = 1 if pidstatus_district == 1 & aq9dx == 1 | aq9dy == 1
replace pidscale_district = 2 if pidstatus_district == 1 & aq9dx == 2 | aq9dy == 2
replace pidscale_district = 3 if pidstatus_district == 1 & aq9dx == 3 | aq9dy == 3
replace pidscale_district = 4 if pidstatus_district == 2
replace pidscale_district = 5 if pidstatus_district == 3 & aq9dx == 3 | aq9dy == 3
replace pidscale_district = 6 if pidstatus_district == 3 & aq9dx == 2 | aq9dy == 2
replace pidscale_district = 7 if pidstatus_district == 3 & aq9dx == 1 | aq9dy == 1

label define pidscale 1 "Strong loser PID" 2 "Moderate loser PID" 3 "Weak loser PID" 4 "No PID" 5 "Weak winner PID" 6 "Moderate winner PID" 7 "Strong winner PID" 
label values pidscale_district pidscale

* Party identification (national)

gen pidstatus_whole = .

replace pidstatus_whole = 9999 if partyid == 98 & partycloser == 98 | partyid == 99 & partycloser == 99 | partyid == 98 & partycloser == 99 | partyid == 98 & partycloser == 99 | partyid == 98 & partycloser == .

replace pidstatus_whole = 2 if partyid == 0 & closer == . & pidstatus_whole!=9999 | partyid == 0 & closer == 2 & pidstatus_whole!=9999 | partyid == 0 & closer == 8 & pidstatus_whole!=9999 | partyid == 0 & closer == 9 & pidstatus_whole!=9999 | partycloser == 0

replace pidstatus_whole = 3 if partyid == 1 & pidstatus_whole!=2 & pidstatus_whole!=9999
replace pidstatus_whole = 3 if partycloser == 1 & pidstatus_whole!=2 & pidstatus_whole!=9999

replace pidstatus_whole = 1 if partyid!=1 & partyid!=. & pidstatus_whole!=2 & pidstatus_whole!=3 & pidstatus_whole!=9999
replace pidstatus_whole = 1 if partycloser!=1 & partycloser!=. & pidstatus_whole!=2 & pidstatus_whole!=3 & pidstatus_whole!=9999

replace pidstatus_whole = . if pidstatus_whole == 9999

label values pidstatus_whole pidstatus

* Party identification scale (national)

gen pidscale_whole = .

replace pidscale_whole = 1 if pidstatus_whole == 1 & aq9dx == 1 | aq9dy == 1
replace pidscale_whole = 2 if pidstatus_whole == 1 & aq9dx == 2 | aq9dy == 2
replace pidscale_whole = 3 if pidstatus_whole == 1 & aq9dx == 3 | aq9dy == 3
replace pidscale_whole = 4 if pidstatus_whole == 2
replace pidscale_whole = 5 if pidstatus_whole == 3 & aq9dx == 3 | aq9dy == 3
replace pidscale_whole = 6 if pidstatus_whole == 3 & aq9dx == 2 | aq9dy == 2
replace pidscale_whole = 7 if pidstatus_whole == 3 & aq9dx == 1 | aq9dy == 1

label values pidscale_whole pidscale

* Political discussion with spouse or partner

gen discussion_partner = cq26a

recode discussion_partner 7=4 9=. 99=.

replace discussion_partner = 4 - discussion_partner

gen discussion_partner_3pts = discussion_partner
replace discussion_partner_3pts = 0 if discussion_partner == 1
replace discussion_partner_3pts = 1 if discussion_partner == 2
replace discussion_partner_3pts = 2 if discussion_partner == 3

* Political discussion with other family members

gen discussion_family = cq26b

recode discussion_family 7=4 9=. 99=.

replace discussion_family = 4 - discussion_family

gen discussion_family_3pts = discussion_family
replace discussion_family_3pts = 0 if discussion_family == 1
replace discussion_family_3pts = 1 if discussion_family == 2
replace discussion_family_3pts = 2 if discussion_family == 3

* Political discussion with friends

gen discussion_friends = cq26c

recode discussion_friends 7=4 9=. 99=.

replace discussion_friends = 4 - discussion_friends

gen discussion_friends_3pts = discussion_friends
replace discussion_friends_3pts = 0 if discussion_friends == 1
replace discussion_friends_3pts = 1 if discussion_friends == 2
replace discussion_friends_3pts = 2 if discussion_friends == 3

* Political discussion with neighbours

gen discussion_neighbours = cq26d

recode discussion_neighbours 7=4 9=. 99=.

replace discussion_neighbours = 4 - discussion_neighbours

gen discussion_neighbours_3pts = discussion_neighbours
replace discussion_neighbours_3pts = 0 if discussion_neighbours == 1
replace discussion_neighbours_3pts = 1 if discussion_neighbours == 2
replace discussion_neighbours_3pts = 2 if discussion_neighbours == 3

* Political discussion with fellow workers

gen discussion_coworkers = cq26e

recode discussion_coworkers 7=4 9=. 99=.

replace discussion_coworkers = 4 - discussion_coworkers

gen discussion_coworkers_3pts = discussion_coworkers
replace discussion_coworkers_3pts = 0 if discussion_coworkers == 1
replace discussion_coworkers_3pts = 1 if discussion_coworkers == 2
replace discussion_coworkers_3pts = 2 if discussion_coworkers == 3

* Political discussion

gen discussion = discussion_partner + discussion_family + discussion_friends + discussion_neighbours + discussion_coworkers

egen discussion_3pts = rowmax(discussion_partner_3pts discussion_family_3pts discussion_friends_3pts discussion_neighbours_3pts discussion_coworkers_3pts)

* Spouse or partner party support

gen disagreement_partner = cq27a

recode disagreement_partner 7=1 8=. 9=. 99=.

replace disagreement_partner = disagreement_partner - 1

* Family members party support

gen disagreement_family = cq27b

recode disagreement_family 7=1 8=. 9=. 99=.

replace disagreement_family = disagreement_family - 1

* Friends party support

gen disagreement_friends = cq27c

recode disagreement_friends 7=1 8=. 9=. 99=.

replace disagreement_friends = disagreement_friends - 1

* Neighbours party support

gen disagreement_neighbours = cq27d

recode disagreement_neighbours 7=1 8=. 9=. 99=.

replace disagreement_neighbours = disagreement_neighbours - 1

* Fellow workers party support

gen disagreement_coworkers = cq27e

recode disagreement_coworkers 7=1 8=. 9=. 99=.

replace disagreement_coworkers = disagreement_coworkers - 1

* Disagreement

gen disagreement = disagreement_partner + disagreement_family + disagreement_friends + disagreement_neighbours + disagreement_coworkers

egen disagreement_3pts = rowmax(disagreement_partner disagreement_family disagreement_friends disagreement_neighbours disagreement_coworkers)

* Talk to people in neighbourhood

gen talk_neighbourhood = cq31d

recode talk_neighbourhood 9=. 99=.

replace talk_neighbourhood = 5 - talk_neighbourhood

* Years lived in neighbourhood

gen years_neighbourhood = cq29

recode years_neighbourhood 99=. 999=.

* Care about outcome

gen care_whole = cq1

recode care_whole 8=. 9=. 99=. 2=0

* Polling stations close at 10.00pm on election day - Correct answer (true) = 1, Incorrect answer = 0

gen stations = bq64a

recode stations 2=0 9=0 99=.

* The Liberal Democrats favour a system of proportional representation for Westminster elections - Correct answer (true) = 1, Incorrect answer = 0

gen libdempr = bq64b

recode libdempr 2=0 9=0 99=.

* The minimum voting age is 16 - Correct answer (false) = 1, Incorrect answer = 0

gen votingage = bq64c

recode votingage 1=0 2=1 9=0 99=.

* The standard rate of income tax payable is 26p in the pound - Correct answer (false) = 1, Incorrect answer = 0

gen incometax = bq64d

recode incometax 1=0 2=1 9=0 99=.

* The Chancellor of the Exchequer is responsible for setting interest rates in the UK - Correct answer (false) = 1, Incorrect answer = 0

gen interestrates = bq64e

recode interestrates 1=0 2=1 9=0 99=.

* Labour wants university students to pay a fee of up to £3,000 each year for their education - Correct answer (true) = 1, Incorrect answer = 0

gen fee = bq64f

recode fee 2=0 9=0 99=.

* The Conservative Party favours imposing strict limits on the number of asylum-seekers who can enter Britain each year - Correct answer (true) = 1, Incorrect answer = 0

gen asylum = bq64g

recode asylum 2=0 9=0 99=.

* Any registered voter can obtain a postal vote if they want one - by ringing their local council and asking for a postal vote - Correct answer (true) = 1, Incorrect answer = 0

gen postalvote = bq64h

recode postalvote 2=0 9=0 99=.

* Political knowledge index

gen knowledge = stations + libdempr + votingage + incometax + interestrates + fee + asylum + postalvote


*********************************
** DISTRICT-LEVEL EXPECTATIONS ** 
*********************************

gen region3 = 1 if aregion >= 1 & aregion < 10
replace region3 = 2 if aregion == 11
replace region3 = 3 if aregion == 10

gen lab_chance_district = aq12a // Labour candidate's probability of winning in district
gen con_chance_district = aq12b // Conservative candidate's probability of winning in district
gen ld_chance_district = aq12c // Liberal Democrat candidate's probability of winning in district
gen ukip_chance_district = aq12d // UKIP candidate's probability of winning in district
gen snp_chance_district = aq12e // SNP candidate's probability of winning in district
gen pc_chance_district = aq12f // PC candidate's probability of winning in district

* Generate variable identifying incomplete answers (PC in Wales only, SNP in Scotland only)

gen complete_district_england = 0 if lab_chance_district == . & region3 == 1 | con_chance_district == . & region3 == 1 | ld_chance_district == . & region3 == 1 | ukip_chance_district == . & region3 == 1
replace complete_district_england = 1 if lab_chance_district!=. & con_chance_district!=. & ld_chance_district!=. & region3 == 1 & ukip_chance_district!=. & region3 == 1

gen complete_district_scotland = 0 if lab_chance_district == . & region3 == 2 | con_chance_district == . & region3 == 2 | ld_chance_district == . & region3 == 2 | snp_chance_district == . & region3 == 2
replace complete_district_scotland = 1 if lab_chance_district!=. & con_chance_district!=. & ld_chance_district!=. & snp_chance_district!=. & region3 == 2

gen complete_district_wales = 0 if lab_chance_district == . & region3 == 3 | con_chance_district == . & region3 == 3 | ld_chance_district == . & region3 == 3 | pc_chance_district == . & region3 == 3
replace complete_district_wales = 1 if lab_chance_district!=. & con_chance_district!=. & ld_chance_district!=. & pc_chance_district!=. & region3 == 3

gen complete_district = max(complete_district_england,complete_district_wales,complete_district_scotland)

* Generate value of 1 if the expectation for one candidate is higher or equal to the expectations for at least one other candidate (England)

gen lab_win_england = 1 if lab_chance_district >= con_chance_district & lab_chance_district >= ld_chance_district & lab_chance_district >= ukip_chance_district & region3 == 1 & complete_district_england == 1

gen con_win_england = 1 if con_chance_district >= lab_chance_district & con_chance_district >= ld_chance_district & con_chance_district >= ukip_chance_district & region3 == 1 & complete_district_england == 1

gen ld_win_england = 1 if ld_chance_district >= lab_chance_district & ld_chance_district >= con_chance_district & ld_chance_district >= ukip_chance_district & region3 == 1 & complete_district_england == 1

gen ukip_win_england = 1 if ukip_chance_district >= lab_chance_district & ukip_chance_district >= con_chance_district & ukip_chance_district >= ld_chance_district & region3 == 1 & complete_district_england == 1

gen oth_win_england = 1 if lab_chance_district == 0 & con_chance_district == 0 & ld_chance_district == 0 & ukip_chance_district == 0 & region3 == 1 & complete_district_england == 1

* Generate value of 1 if the expectation for one candidate is higher or equal to the expectations for at least one other candidate (Scotland)

gen lab_win_scotland = 1 if lab_chance_district >= con_chance_district & lab_chance_district >= ld_chance_district & lab_chance_district >= snp_chance_district & region3 == 2 & complete_district_scotland == 1

gen con_win_scotland = 1 if con_chance_district >= lab_chance_district & con_chance_district >= ld_chance_district & con_chance_district >= snp_chance_district & region3 == 2 & complete_district_scotland == 1

gen ld_win_scotland = 1 if ld_chance_district >= lab_chance_district & ld_chance_district >= con_chance_district & ld_chance_district >= snp_chance_district & region3 == 2 & complete_district_scotland == 1

gen snp_win_scotland = 1 if snp_chance_district >= lab_chance_district & snp_chance_district >= con_chance_district & snp_chance_district >= ld_chance_district & region3 == 2 & complete_district_scotland == 1

gen oth_win_scotland = 1 if lab_chance_district == 0 & con_chance_district == 0 & ld_chance_district == 0 & snp_chance_district == 0 & region3 == 2 & complete_district_scotland == 1

* Generate value of 1 if the expectation for one candidate is higher or equal to the expectations for at least one other candidate (Wales)

gen lab_win_wales = 1 if lab_chance_district >= con_chance_district & lab_chance_district >= ld_chance_district & lab_chance_district >= pc_chance_district & region3 == 3 & complete_district_wales == 1

gen con_win_wales = 1 if con_chance_district >= lab_chance_district & con_chance_district >= ld_chance_district & con_chance_district >= pc_chance_district & region3 == 3 & complete_district_wales == 1

gen ld_win_wales = 1 if ld_chance_district >= lab_chance_district & ld_chance_district >= con_chance_district & ld_chance_district >= pc_chance_district & region3 == 3 & complete_district_wales == 1

gen pc_win_wales = 1 if pc_chance_district >= lab_chance_district & pc_chance_district >= con_chance_district & pc_chance_district >= ld_chance_district & region3 == 3 & complete_district_wales == 1

gen oth_win_wales = 1 if lab_chance_district == 0 & con_chance_district == 0 & ld_chance_district == 0 & pc_chance_district == 0 & region3 == 3 & complete_district_wales == 1

* Combine

gen lab_district = max(lab_win_england,lab_win_scotland,lab_win_wales) if complete_district == 1
gen con_district = max(con_win_england,con_win_scotland,con_win_wales) if complete_district == 1
gen ld_district = max(ld_win_england,ld_win_scotland,ld_win_wales) if complete_district == 1
gen ukip_district = ukip_win_england if complete_district == 1
gen snp_district = snp_win_scotland if complete_district == 1
gen pc_district = pc_win_wales if complete_district == 1
gen oth_district = max(oth_win_england,oth_win_scotland,oth_win_wales) if complete_district == 1

replace lab_district = . if oth_district == 1 & complete_district == 1
replace con_district = . if oth_district == 1 & complete_district == 1
replace ld_district = . if oth_district == 1 & complete_district == 1
replace ukip_district = . if oth_district == 1 & complete_district == 1
replace snp_district = . if oth_district == 1 & complete_district == 1
replace pc_district = . if oth_district == 1 & complete_district == 1

* Generate variable for ambiguous forecasts

gen ambiguous_district = .

replace ambiguous_district = 99 if lab_district == con_district & lab_district!=. & complete_district == 1 | lab_district == ld_district & lab_district!=. & complete_district == 1 | lab_district == ukip_district & lab_district!=. & complete_district == 1 | lab_district == snp_district & lab_district!=. & complete_district == 1 | lab_district == pc_district & lab_district!=. & complete_district == 1

replace ambiguous_district = 99 if con_district == lab_district & con_district!=. & complete_district == 1 | con_district == ld_district & con_district!=. & complete_district == 1 | con_district == ukip_district & con_district!=. & complete_district == 1 | con_district == snp_district & con_district!=. & complete_district == 1 | con_district == pc_district & con_district!=. & complete_district == 1

replace ambiguous_district = 99 if ld_district == lab_district & ld_district!=. & complete_district == 1 | ld_district == con_district & ld_district!=. & complete_district == 1 | ld_district == ukip_district & ld_district!=. & complete_district == 1 | ld_district == snp_district & ld_district!=. & complete_district == 1 | ld_district == pc_district & ld_district!=. & complete_district == 1

replace ambiguous_district = 99 if ukip_district == lab_district & ukip_district!=. & complete_district == 1 | ukip_district == con_district & ukip_district!=. & complete_district == 1 | ukip_district == ld_district & ukip_district!=. & complete_district == 1 | ukip_district == snp_district & ukip_district!=. & complete_district == 1 | ukip_district == pc_district & ukip_district!=. & complete_district == 1

replace ambiguous_district = 99 if snp_district == lab_district & snp_district!=. & complete_district == 1 | snp_district == con_district & snp_district!=. & complete_district == 1 | snp_district == ld_district & snp_district!=. & complete_district == 1 | snp_district == ukip_district & snp_district!=. & complete_district == 1 | snp_district == pc_district & snp_district!=. & complete_district == 1

* Generate value of 0 for lower expectations

replace lab_district = 0 if lab_district!=1 & complete_district == 1
replace con_district = 0 if con_district!=1 & complete_district == 1
replace ld_district = 0 if ld_district!=1 & complete_district == 1
replace ukip_district = 0 if ukip_district!=1 & complete_district == 1
replace snp_district = 0 if snp_district!=1 & complete_district == 1
replace pc_district = 0 if pc_district!=1 & complete_district == 1
replace oth_district = 0 if oth_district!=1 & complete_district == 1

* Forecasts (2 = Labour, 3 = Conservative, 4 = Liberal Democrat, 5 = SNP, 6 = PC, 7 = Green, 8 = UKIP, 9 = BNP, 10 = other, 99 = ambiguous)

gen forecast_district = .

replace forecast_district = 1 if lab_district == 1 & complete_district == 1
replace forecast_district = 2 if con_district == 1 & complete_district == 1
replace forecast_district = 3 if ld_district == 1 & complete_district == 1
replace forecast_district = 6 if ukip_district == 1 & complete_district == 1
replace forecast_district = 4 if snp_district == 1 & complete_district == 1
replace forecast_district = 5 if pc_district == 1 & complete_district == 1
replace forecast_district = 10 if oth_district == 1 & complete_district == 1
replace forecast_district = 99 if ambiguous_district == 99 & complete_district == 1

* Identify correct and ambiguous forecasts

gen correct_district = 0 if forecast_district!=constituency_2005 & forecast_district!=99 & constituency_2005!=. & complete_district == 1
replace correct_district = 1 if forecast_district == constituency_2005 & forecast_district!=99 & constituency_2005!=. & complete_district == 1

replace correct_district = 0 if forecast_district == 99 & lab_district!=1 & constituency_2005 == 2 & complete_district == 1
replace correct_district = 0 if forecast_district == 99 & con_district!=1 & constituency_2005 == 3 & complete_district == 1
replace correct_district = 0 if forecast_district == 99 & ld_district!=1 & constituency_2005 == 4 & complete_district == 1
replace correct_district = 0 if forecast_district == 99 & ukip_district!=1 & constituency_2005 == 5 & complete_district == 1
replace correct_district = 0 if forecast_district == 99 & snp_district!=1 & constituency_2005 == 6 & complete_district == 1
replace correct_district = 0 if forecast_district == 99 & pc_district!=1 & constituency_2005 == 6 & complete_district == 1
replace correct_district = 0 if forecast_district == 99 & oth_district!=1 & constituency_2005 == 10 & complete_district == 1

replace correct_district = 99 if correct_district == . & constituency_2005!=. & complete_district == 1

* Generate dichotomous variable (treat ambiguous forecasts as incorrect)

gen correct_district_d = correct_district

replace correct_district_d = 0 if correct_district_d == 99
replace correct_district_d = 1 if correct_district_d == 1


*********************************
** NATIONAL-LEVEL EXPECTATIONS ** 
*********************************

gen lab_chance_whole = aq13a // Labour party's probability of winning the election
gen con_chance_whole = aq13b // Conservative party's probability of winning the election
gen ld_chance_whole = aq13c // Liberal Democrats' probability of winning the election

* Generate variable identifying incomplete answers

gen complete_whole = 0 if lab_chance_whole == . | con_chance_whole == . | ld_chance_whole == .
replace complete_whole = 1 if lab_chance_whole!=. & con_chance_whole!=. & ld_chance_whole!=.

* Generate value of 1 if the expectation for one party is higher or equal to the expectations for at least one other party

gen lab_whole = 1 if lab_chance_whole >= con_chance_whole & lab_chance_whole >= ld_chance_whole & complete_whole == 1

gen con_whole = 1 if con_chance_whole >= lab_chance_whole & con_chance_whole >= ld_chance_whole & complete_whole == 1

gen ld_whole = 1 if ld_chance_whole >= lab_chance_whole & ld_chance_whole >= con_chance_whole & complete_whole == 1

gen oth_whole = 1 if lab_chance_whole == 0 & con_chance_whole == 0 & ld_chance_whole == 0 & complete_whole == 1

replace lab_whole = . if oth_whole == 1 & complete_whole == 1
replace con_whole = . if oth_whole == 1 & complete_whole == 1
replace ld_whole = . if oth_whole == 1 & complete_whole == 1

* Generate variable for ambiguous forecasts

gen ambiguous_whole = .

replace ambiguous_whole = 99 if lab_whole == con_whole & lab_whole!=. & complete_whole == 1 | lab_whole == ld_whole & lab_whole!=. & complete_whole == 1

replace ambiguous_whole = 99 if con_whole == lab_whole & con_whole!=. & complete_whole == 1 | con_whole == ld_whole & con_whole!=. & complete_whole == 1

replace ambiguous_whole = 99 if ld_whole == lab_whole & ld_whole!=. & complete_whole == 1 | ld_whole == con_whole & ld_whole!=. & complete_whole == 1

* Generate value of 0 for lower expectations

replace lab_whole = 0 if lab_whole!=1 & lab_whole!=. & complete_whole == 1
replace con_whole = 0 if con_whole!=1 & con_whole!=. & complete_whole == 1
replace ld_whole = 0 if ld_whole!=1 & ld_whole!=. & complete_whole == 1
replace oth_whole = 0 if oth_whole!=1 & oth_whole!=. & complete_whole == 1

* Forecasts (1 = Labour, 2 = Conservative, 3 = Liberal Democrat, 10 = other, 99 = ambiguous)

gen forecast_whole = .

replace forecast_whole = 1 if lab_whole == 1 & complete_whole == 1
replace forecast_whole = 2 if con_whole == 1 & complete_whole == 1 
replace forecast_whole = 3 if ld_whole == 1 & complete_whole == 1
replace forecast_whole = 10 if oth_whole == 1 & complete_whole == 1
replace forecast_whole = 99 if ambiguous_whole == 99 & complete_whole == 1

* Identify correct and ambiguous forecasts

gen correct_whole = 0 if forecast_whole!=1 & forecast_whole!=99 & forecast_whole!=. & complete_whole == 1
replace correct_whole = 1 if forecast_whole == 1 & forecast_whole!=99 & forecast_whole!=. & complete_whole == 1
replace correct_whole = 99 if forecast_whole == 99 & complete_whole == 1

* Generate dichotomous variable (treat ambiguous forecasts as incorrect)

gen correct_whole_d = correct_whole

replace correct_whole_d = 0 if correct_whole_d == 99
replace correct_whole_d = 1 if correct_whole_d == 1


**********
** SAVE **
**********

save "gb2005_bes.dta", replace


*******************
** MAIN ANALYSES **
*******************

* Regression analysis and percentage of correct and incorrect forecasts (national)

logistic correct_whole_d discussion disagreement pidscale_whole interest knowledge i.care_whole age i.male education time
estimates table, star(.05 .01 .001)

tab correct_whole_d if e(sample) == 1

* Regression analysis and percentage of correct and incorrect forecasts (district)

melogit correct_district_d discussion disagreement pidscale_district interest knowledge age i.male education time enep || district_name: , or
estimates table, star(.05 .01 .001)

tab correct_district_d if e(sample) == 1


************************
** SUMMARY STATISTICS **
************************

label variable correct_whole_d "Election winner (DV)"
label variable correct_district_d "District winner (DV)"
label variable discussion "Discussion"
label variable disagreement "Disagreement"
label variable pidscale_whole "National PID"
label variable pidscale_district "District PID"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable interest "Interest"
label variable care_whole "Caring about outcome"
label variable knowledge "Political knowledge"
label variable time "Time of interview"
label variable enep "ENEP"
label variable margin "Margin"

quietly logistic correct_whole_d discussion disagreement pidscale_whole interest knowledge i.care_whole age i.male education time

estpost tabstat correct_whole_d discussion disagreement pidscale_whole interest knowledge care_whole age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "gb2005_bes_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.1f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2005 British general election (BES), national level") replace

eststo clear

quietly melogit correct_district_d discussion disagreement pidscale_district interest knowledge age i.male education time enep || district_name: , or

estpost tabstat correct_district_d discussion disagreement pidscale_district interest knowledge age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "gb2005_bes_summary_district.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.1f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2005 British general election (BES), district level") replace

eststo clear

log close